eventtrigger - jQuery trigger click for function with e.target -
i've had issues jquery .trigger()
in past, works , others not. breaks down when need ...
html
<div class="list"> <a href="#" class="one">one</a> <a href="#" class="two">two</a> <a href="#" class="three">three</a> </div> <p class="output"></p>
js
$(document).ready(function() { $('.two').trigger('click'); $('.list a').click(function(e){ e.preventdefault(); $text = $(e.target).text(); $('.output').text($text); }); });
fiddle: http://jsfiddle.net/7pup2/
you need register handler first trigger event
it should be
$(document).ready(function() { $('.list a').click(function(e){ e.preventdefault(); $text = $(e.target).text(); $('.output').text($text); }); $('.two').trigger('click'); });
Comments
Post a Comment