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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -