javascript - Trying to swap the title attribute of a paragraph with the content of the paragraph -
for example want change html :
<p title="title text">content text</p>
into this:
<p title="content text">title text</p>
so far have code make title
value equal in <p>
window.addeventlistener("load",init); function init(){ var b = document.queryselector("p"); b.setattribute("title",b.textcontent); console.log(b); }
swap them using variable holds value while updating
window.addeventlistener("load", init); function init() { var b = document.queryselector("p"); var temp = b.textcontent; b.textcontent = b.getattribute("title"); b.setattribute("title", temp); console.log(b); }
<p title="title text">content text</p>
Comments
Post a Comment