search

Home  >  Q&A  >  body text

javascript - Get the content in the tag and assign it to the title?

<p title="">嗨,你的title</p>

Assign "Hi, your title" to title

大家讲道理大家讲道理2714 days ago879

reply all(3)I'll reply

  • 滿天的星座

    滿天的星座2017-06-26 10:56:29

    var elem = document.querySelector("p");
    elem.setAttribute("title", elem.innerText);

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-06-26 10:56:29

    $("p").attr("title",$("p").text());

    reply
    0
  • 给我你的怀抱

    给我你的怀抱2017-06-26 10:56:29

    I don’t know what specific function you want, but if you want to assign a value, you can:

     <p title="" class="title">赋值啊啊啊啊</p>
        
        <script>
            let txt = $('.title').text();
            $('.title').attr('title',txt);
        </script>

    reply
    0
  • Cancelreply