Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
26
rated 0 times [  33] [ 7]  / answers: 1 / hits: 15160  / 9 Years ago, thu, october 1, 2015, 12:00:00

I would like to click a li tag when page loads but it is not working.
HTML:



 <div id=listDiv>
<ul id=listUL class=listUL>
<li id=f1 class=listDynamic>Term1</li>
<li id=f2 class=listDynamic>Term2</li>
<li id=f3 class=listDynamic >Term3</li>
</ul>
</div>


JavaScript:



$(#listUL).find(li#f1).click(function() {
alert(clicked: + this.id);
});
$(#listUL).find(li#f1).trigger(click);

/*
I also tried
$( document ).ready(function() {
$(#listUL).find(li#f1).trigger(click);
});

*/


http://jsfiddle.net/hx20d87m/4/


More From » jquery

 Answers
2
$(function() {
$(li#f1).click(function() {
alert(clicked: + this.id);
});

$(li#f1).trigger(click);
});


https://jsfiddle.net/yz8owa76/


[#64872] Tuesday, September 29, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
meadowe

Total Points: 0
Total Questions: 97
Total Answers: 97

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;