Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the inner html value

Tags:

javascript

var str_f = document.getElementById("" + j + "").innerHTML;

<p>
  <span style="color: red">advertising cctv/bust</span>
  <span style="color: red">a</span>tion
</p>

how can i get the value

like image 855
sampath Avatar asked Nov 08 '25 15:11

sampath


2 Answers

If you want to get the innerHTML of the <p> tag then give it an id and then use the following code

<p id="para1"><span style="color: red"> advertising cctv/bust</span><span style="color: red">a</span>tion </p>


document.getElementById("para1").innerHTML;

If you want to get text content inside the element then you can use

var elem = document.getElementById("para1");
var elementText = x.innerText || x.textContent
like image 80
rahul Avatar answered Nov 11 '25 03:11

rahul


This won't work, your doing a getElementById but you don't have any elements with Id's...

like image 28
Zachary Avatar answered Nov 11 '25 04:11

Zachary



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!