Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
136
rated 0 times [  143] [ 7]  / answers: 1 / hits: 21458  / 13 Years ago, wed, october 5, 2011, 12:00:00
<ul>
<li>
<span class=name>Tortilla de blé</span>
</li>
</ul>


This is the original source. I need to change the background Color of just the text in the tag.
I have used css property background-color for it. But it is changing the color of the whole list item.
i have to change the background color only by using javascript.



var ea = document.getElementsByClassName('name');
for(var i = 0; i < ea.length; i++)
ea[i].style.backgroundColor = yellow;


(Changed the Older Script as that was not correct, mistakenly written)



My Result:



Original



Expected Result:
What could i do to just highlight the text in the tag and not the whole tag.



Expected



I have produced the expected result by editing the source code like below:



<ul>
<li>
<span class=name><font style=bakground-color:yellow>Tortilla de blé</font></span>
</li>
</ul>


By Embedding font tag to the text which is not possible with the javascript.
I have done this with the help of Inspect Element feature of Google Chrome


More From » html

 Answers
15
[#89784] Monday, October 3, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ethanc

Total Points: 57
Total Questions: 111
Total Answers: 111

Location: Vanuatu
Member since Fri, May 13, 2022
2 Years ago
;