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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -