Awesome q2a theme

How to style an element, knowing its ID?

0 like 0 dislike
39 views
Good day!
There are the following elements:


The button ID has a numerical format, from [1..100] and above.
The crux of the matter is that I need to add a class to an element i to a certain key, namely the one on which the click event.

The function of the following:
function getButton(el) { id = el.id; $().addClass('fa fa-circle-o-notch fa-spin'); }


Please tell me how to access the button with a certain ID so that when clicked, class addClass('fa fa-circle-o-notch fa-spin') was added to a specific button, but not to all?

Thank you very much!
by | 39 views

3 Answers

0 like 0 dislike
As I understand it, the class you need to add the i element inside the button, and the handler is hanging on the button, so
function getButton(el) { //here el is the specific button that was pressed and passed to the function $('i', $(el)).addClass('fa fa-circle-o-notch fa-spin'); //or $(el).find('i').addClass('fa fa-circle-o-notch fa-spin'); //or $(el).children('i').addClass('fa fa-circle-o-notch fa-spin'); //so all will be applied to the element i specific the button is pressed }
by
0 like 0 dislike
namely the one on which the click event.

it does not need selectors



function getButton(event) { // in parameter to be passed the click event // this will reference the DOM element on which the event occurred $(this).addClass('fa fa-circle-o-notch fa-spin'); }
by
0 like 0 dislike
function getButton(el) { id = el.id; $(el).addClass('fa fa-circle-o-notch fa-spin'); }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
0 comments
40,796 users