admin管理员组

文章数量:1406060

js code snippet that goes like this:

function currency_change(value) {

  // change all currencies on the page
  $$('label.currency').each(function() {

    this.innerHTML = value;

  });
  alert(value);

}

I know value is correct and I know I'm traversing over each label.currency class, but I can't seem to change the innerHTML values of these elements.

I googled like crazy, but I can't figure out how to do this. I suspect something is wrong with this.

js code snippet that goes like this:

function currency_change(value) {

  // change all currencies on the page
  $$('label.currency').each(function() {

    this.innerHTML = value;

  });
  alert(value);

}

I know value is correct and I know I'm traversing over each label.currency class, but I can't seem to change the innerHTML values of these elements.

I googled like crazy, but I can't figure out how to do this. I suspect something is wrong with this.

Share Improve this question edited Feb 11, 2016 at 8:08 bpoiss 14k4 gold badges37 silver badges49 bronze badges asked Sep 3, 2011 at 2:31 Danny_JorisDanny_Joris 3996 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Try this:

$$('label.currency').each(function(element) {
    element.update(value);
});
$$('label.currency').invoke('update',value);

IE shows very poor performance when replacing plex DOM trees. In such cases remove the inner DOM before updating:

$$('label.currency').invoke('childElements').invoke('invoke','remove');

If it's one single Element you can say:

$('elementID').childElements().invoke('remove');

本文标签: javascriptthisinnerHTML in PrototypeStack Overflow