简体   繁体   中英

radio button of a class clicked jquery

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.

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
    }
});

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+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM