Friday 15 February 2013

javascript - Replace the text of span element -


I want to change the square icon (text in the span element to a HTML file with an arrow: ■): ►. This occurs when this icon matches the page ID in front of the menu icon, so that the visitor knows that it is on the page indicated by this menu item.

I am passing through many issues but stuck with this one

  var newIcon = "& 9658;"; // arrow icon (var j = 0; j & lt; rightMenuIDs.length; j ++) {var isid = right manual [j]; Var This is SpanIcon = rightMenu [j] Children [0]. Children [0]. ChildNode [0] .nodeValue; If (thisID === bodyIDsliced) {This span icon = newIcon; }}   

I got the console Checked with the log, it indicates that the span icon has been updated as an arrow icon. But nothing has changed on the page.

Is there a better / correct way to do this?

Thank you!

When you say:

  ThisSpanIcon = newIcon;   

You are simply overwriting the local variable thisSpanIcon in which the copy current nodeValue The property, property (and after that node) does not change.

Try:

  var This is SpanNode = rightMenu [j]. Children [0]. Children [0] .childNodes [0]; If (thisID === bodyIDsliced) {thisSpanNode.nodeValue = newIcon; }   

Instead, the actual property of the node should be changed.

Also keep in mind that you should use the Unicode format rather than an HTML unit, i.e. \ U25ba .

No comments:

Post a Comment