Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
here: $(function(){ var tags = document.getElementsByTagName("eval"); for (var i=0; i<tags.length; i++) { tags[i].innerHTML = eval(tags[i].innerHTML); } });
18th Aug 2019, 10:30 PM
Anton Böhler
Anton Böhler - avatar
+ 3
When you getElementsByTagName, you get all elements with that tag name. Invoke each of them using an index. var evaler = document.getElementsByTagName("eval")[0]; You also want to eval() the contents of the element, not the element itself. evaler.innerHTML = eval(evaler.innerHTML) After fixing these two things, your code will display 60.
17th Aug 2019, 12:55 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
html: <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.js"></script> <title>Page Title</title> </head> <body> <p id="ev">55+5</p> </body> </html> js: $(function(){ var evaler = document.getElementById("ev"); evaler.innerHTML = eval(evaler.innerHTML) }); do you want this?! 😅
17th Aug 2019, 12:59 PM
Anton Böhler
Anton Böhler - avatar
+ 2
go throw all elements you get from 'getElementsByTagName' with a for loop and evaluate them
18th Aug 2019, 10:20 PM
Anton Böhler
Anton Böhler - avatar