Saturday 14 September 2019

Get value from attribute with javascript

Answer




I have the following code:



echo "
";


In this case, val has the value 8.



I want to access this value with javascript. I have tried the followin method, but it keeps saying that txt is null.



  


Anyone who can help me?



EDIT:
I solved the problem by placing the code inside window.onload:




    window.onload = function() {
var txt = document.getElementById("hp");
var f = txt.getAttribute('val');
alert(f);
};

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...