Jquery on() load event on a single element -


i'm sorry if question has been asked, didn't find solution.

i have 3 radios elements , want check value when selection changes , when page loads.

i using on() function.

my problem change event triggered.

here current code :

$('.user').on('load change', function(){   if($(this).val() == 'client'){  $('#user_parent').removeattr('disabled').closest('tr').show(200); }else{   $('#user_parent').attr('disabled', 'disabled').closest('tr').hide(200); } });" 

i tried replace load ready, failed too. problem ? isn't load event available single element ?

the code placed in $(document).ready(...), , elements displayed when page sent.

thanks

the load event called moment child elements of listened element loaded. in case might before ready event called, rendering handler load (which appended after document.ready) useless.

for reference see jquery api find following:

the load event sent element when , sub-elements have been loaded. event can sent element associated url: images, scripts, frames, iframes, , window object.

this means need url, can listen load event. have not provided further code assume indeed have url can listen to.

this might probable cause though. if not have url associated (at least one) child element(s) there no load event can listen to.

try instead:

$(document).ready(function(){    checkuserval();    $('.user').on('change', checkuserval); });  var checkuserval = function(){   //do check   if($('.user').val() == 'client'){       $('#user_parent').removeattr('disabled').closest('tr').show(200);   }else{      $('#user_parent').attr('disabled', 'disabled').closest('tr').hide(200);   } }; 

i made code method improved readability ;)


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -