dom - How can I list the contents of all the <p> elements in the console using JavaScript? -


i'm trying log content of <p> elements in console pressing on button here code far.

window.addeventlistener("load",init); function init(){          var b = document.getelementbyid("btn2")         b.addeventlistener("click",action) } function action(){     var i, items = document.qetelementsbytagname("p");      (i = 0; < items.length; i++) {           console.log(items[i]);      } } 

get content using innerhtml or textcontent property

console.log(items[i].innerhtml);  //or console.log(items[i].textcontent); 

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) -