0

I'm trying to work out how to add a class to a child element of a button, specifically to the <i> below:

<button><i class="icon-undo"></i> Undo</button>

Ideally, using plain JavaScript, there'd be a function which can be added to the button (i.e. <button onclick="function()">) which would add the class "icon-spin" to the child <i> of whatever element was clicked (so it could be used in multiple places in the same page).

Robin van Baalen
  • 3,422
  • 2
  • 19
  • 33
Rich Jenks
  • 1,441
  • 5
  • 18
  • 30
  • "Button tag: not worth the trouble, just use input for now." [source](http://stackoverflow.com/questions/1903453/what-disadvantages-are-there-to-the-button-tag-it-seems-there-are-quite-a-fe) – jbabey Jan 23 '13 at 15:35
  • Why even have an in the element? Can't you just add a class to the button and with a some padding get the same result? – epascarello Jan 23 '13 at 15:49
  • It has to be – Rich Jenks Jan 23 '13 at 19:41

1 Answers1

-1

Maybe the code in this question helps.... posted the answer today itself. Just pass 'this' to the function and you could do wonders to the DOM thereafter

get nearby sibling in javascript

Community
  • 1
  • 1
Riju Mahna
  • 5,850
  • 10
  • 49
  • 84
  • in the case where the answer to an older question is also an answer to a new question, the new question should be closed as duplicate, not have the answer copy and pasted from the older question. – jbabey Jan 23 '13 at 15:38