Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
182
rated 0 times [  189] [ 7]  / answers: 1 / hits: 24846  / 7 Years ago, thu, may 11, 2017, 12:00:00

Radio Button



<input name=radio-choice-t-6 class=qololbl id=radio-choice-t-6a value=qolo checked=checked type=radio>
<label for=radio-choice-t-6a style=border: 1px solid #2d5f7c;width:90px;border-bottom-left-radius:4px;border-top-left-radius:4px;font-family:Noto Sans;>Toast</label>

$(document).ready(function (e) {

$('.qololbl').trigger('click');

$(.qololbl).click(function(){
alert(Hi);
});
});


how to fire qololbl click event on document ready. this code is not working why..?
thanks in advance.
help me


More From » jquery

 Answers
3

Use .click() instead of .trigger(). And put it after event hanlder declaration.





$(document).ready(function (e) {

$(.qololbl).click(function(){
alert(Hi);
});

$('.qololbl').click();
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<input name=radio-choice-t-6 class=qololbl id=radio-choice-t-6a value=qolo checked=checked type=radio>
<label for=radio-choice-t-6a style=border: 1px solid #2d5f7c;width:90px;border-bottom-left-radius:4px;border-top-left-radius:4px;font-family:Noto Sans;>Toast</label>





Alternative (Suggested by pratik-gaikwad)





$(document).ready(function (e) {

$(.qololbl).on('click', function(){
alert(Hi);
});

$('.qololbl').trigger('click');
});

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<input name=radio-choice-t-6 class=qololbl id=radio-choice-t-6a value=qolo checked=checked type=radio>
<label for=radio-choice-t-6a style=border: 1px solid #2d5f7c;width:90px;border-bottom-left-radius:4px;border-top-left-radius:4px;font-family:Noto Sans;>Toast</label>




[#57818] Tuesday, May 9, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaisep

Total Points: 748
Total Questions: 95
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
blaisep questions
Wed, Dec 16, 20, 00:00, 4 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Tue, Nov 12, 19, 00:00, 5 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
;