V
V
vadimstroganov2015-11-11 15:09:34
JavaScript
vadimstroganov, 2015-11-11 15:09:34

Dynamic select id?

Hello!
There are many buttons, with id sync_site_1, sync_site_2 etc.
I need to add a class to the pressed button, now I did for one:

$(document).ready ->
  $("#sync_site_1").on("ajax:success", (e, data, status, xhr) ->
    $("#sync_site_1").toggleClass "site_is_sync"
   )

But I don’t understand how to catch a specific class (button number, number at the end of the class)
There can be 100-200 buttons, but you can’t write such code for each of them ..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2015-11-11
@Stalker_RED

$('button[id^="sync_site_"]')- will return all buttons whose id starts withsync_site_

S
Sailaubai Shyngys, 2015-11-11
@chyngys

And classes to use for the selector or other attributes besides id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question