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.
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);
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With