Reputation: 1105
I have following radio button in my page
<input type="radio" name="launch_selection" class="linkToSectionSurvey expandSectionSurvey" id="linkTosectionSurvey1" rel="Surveysection1">
<input type="radio" name="launch_selection" id="all_active_members" class="linkToSectionSurvey expandSectionSurvey">
And this the code in my js file, which I am using for radio button click event.
jQuery('input[type=radio].expandSectionSurvey').live('click',function(e){
});
My requirement is to check the class clicked.
Jquery function is getting called on radio button clicked.
Only issue is its not showing "checked" even after it is clicked.
Its an old application using jquery version 1.4.2, which I cannot upgrade because at almost all places ".live" is used.
Thanks in advance.
Upvotes: 0
Views: 250
Reputation: 588
Add this flie as reference: or use old one
type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"
Use this, it may be helpful
$('input[type=radio].expandSectionSurvey').live('click',function(e){
alert('Test')
});
.live()
$(selector).live(events, data, handler); // jQuery 1.3+
.on()
$(document).on(events, selector, data, handler); // jQuery 1.7+
Upvotes: 0
Reputation: 74738
As this comment says everything:
.live()
was deprecated in jQuery 1.7
, removed in 1.9
. Please convert to .on()
So, Only if your radio elements are dynamically generated/created only in this case you should follow the event delegation
event binding. you have to convert it with .on()
event listener in conjunction with change
event:
jQuery(document).on('change', 'input[type=radio]', function(e){
if($(this).hasClass('expandSectionSurvey')){
// do something
}else{
// do something else
}
});
As per comment jquery v1.4.x:
jQuery('input[type=radio]').live('change', function(e){
if($(this).hasClass('expandSectionSurvey')){
// do something
}else{
// do something else
}
});
Upvotes: 1