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
Post a Comment