Use wildcard ID with jQuery and get wildcard ID
jquery, jquery-selectors, wildcard
Solution
You could always try to extract the id/index like this:
$(document).ready(function() {
$("[id^=hideshow]").click(function() {
var index = parseInt($(this).attr("id").replace('hideshow',''), 10);
});
});
Problem
I have 4 IDs ``` hideshow1 hideshow2 hideshow3 hideshow4 ``` Now when the buttons of those IDs are clicked I want to preform individual actions using those integers on the end. So far I have this: ``` $(document).ready(function() { $("[id^=hideshow]").click(function() { }); }); ``` Which is enough to act on the click for each of those buttons, but I need to extract the integer on the end to use it to only act on the one that was clicked. Example if #hideshow1 is clicked ``` $('#hideshow%').html('Hide'); $('.success%').addClass('test'); ``` Where the % is where the integer would be extracted from the initial hideshow ID.