last day (14 days later) » 

12:49 PM
0
A: Add click event using jQuery to radio buttons with name property

Bhushan KawadkarYou are missing syntax to bind event, need to add function() and then call removeCls inside it. Change this $('input[name^=2aiv]').click(removeCls('2aiv')); to $('input[name^=2aiv]').click(function(){removeCls('2aiv');});

 
I tried this, but nothing seems to happen. It is not adding anything to the radio button...
 
are there duplicate ids in your html. Please check for console errors.
 
no duplicate id. but I do have duplicate names as shown in code.. and console shows no error..
 
duplicate name does not matter. but it is working at my side see this jsfiddle.net/MS3EU/11 are you creating these elements dynamically?
@Parminder, make sure that addClass and click event code should be inside document.ready and keep removeCls function outside it.
 
yes I saw the fiddle its working but I am not able to figure out what is the problem at my end. Any suggestion??
this is what in my actual code $('input[name^='+err_lst[i]+']').click(function(){removeCls(err_lst[i]);});
err_lst is an array which contains all the ids
 
12:51 PM
ids or name?
 
for radio button it is name and for tr it is id value is same for both
 
are these ids ends with aiv always?
 
no all are different 1a, 1b, 1c, 1ci, 1cii, 1ciii, 1civ.... and so on around 350 question in form
 
I hope u hav the idea what i'm trying to achieve..
 
12:54 PM
then why are you using start with selector for name (ie. name^=)
ok
use like this
 
it was just a try I did.. i have actually tried (name=) also
 
$('input[name="'+err_lst[i]+'"]').on("click",function(){removeCls($(this).attr('‌​name'));});
use .on and pass name attribute to removeCls.
let me what happened.
 
ok let me try..
 
1:10 PM
console shows this
TypeError: can't access dead object
TypeError: elem.tagName is undefined
 
elem is null for wherever you are using elem.tagName
how are you getting elem?
 
i have no clue.. I have actually started working with all this few months back and I m kinda new to this field..
can I add 2 condition like :: $('input[name=aiv value=1]')
 
1:29 PM
yes but like this $('input[name=aiv][value=1]')
 

last day (14 days later) »