I have many buttons in one form. I made one script for a few particular buttons and now my other buttons are not working correctly.
Is it possible to make my button script unique for only the designated butons avoiding conflict with other buttons? It appears “input[type=’button’]” applies to all buttons in the form when I only want it to apply to a few in the script.
Here is the script I wish to modify to only work for a few particular buttons:
$(document).ready(function(){
$(function() {
var $buttons = $("input[type='button']");
$buttons.click(function() {
$(this).parent().siblings('.bx, #bxGender .gender').css({'background':'#2F2F2F','color':'#fff'});
$buttons.not(this).removeClass('button-toggle-on');
$(this).toggleClass('button-toggle-on').attr('style','');
var varval = '';
if ($(this).hasClass('button-toggle-on')) {
varval = $(this).hasClass('gnF') ? 'Female' : 'Male';
$(this).siblings('input[type="button"]').css('background-position','0 -180px');
}
else {
$(this).siblings('input[type="button"]').attr('style','');
$(this).parent().siblings('.bx').attr('style','');
}
$("#gender").val(varval);
});});
});
<input type="button" class="gnM" >
<input type="button" class="gnF">
<input class="req-string gender" id="gender" name="gender">
Like this? Here’s an example of using classes to only affect certain elements.