jimfog Posted December 17, 2012 Share Posted December 17, 2012 (edited) When we have 2 functions(one within another), in jquery. just like the code above: $("#test").click(function(){ $(function(){alert("hi"); $(this).append('<img id="rem_service" align="center" src="Images/rem_service.png">'); })return false; }); Is the second function(the inner)going to work as expected-or does it have to be called first, just like in PHP. I think not-in the above example though I only get the alert message-the append method does not work. Before examining other causes for this, I want to make sure first that an inner function(in jquery) works ok even if it is not called. Edited December 17, 2012 by jimfog Link to comment Share on other sites More sharing options...
dsonesuk Posted December 17, 2012 Share Posted December 17, 2012 try $("#test").click(function(){thisselector= $(this); $(function(){alert("hi"); thisselector.append('<img id="rem_service" align="center" src="Images/rem_service.png">'); }) or var thisselector;$("#test").click(function(){thisselector= $(this); $(function(){alert("hi"); thisselector.append('<img id="rem_service" align="center" src="Images/rem_service.png">'); }) Link to comment Share on other sites More sharing options...
jimfog Posted December 20, 2012 Author Share Posted December 20, 2012 What about the original question I made? In jquery, when you attache an event handler to an element...I suppose no need to callthe function.it is just executed as it is. Right? Link to comment Share on other sites More sharing options...
thescientist Posted December 20, 2012 Share Posted December 20, 2012 (edited) right, that's how event handlers in javascript work. you assign a function so that when that event happens, the function will be called (i.e. the event is handled by that function). Edited December 20, 2012 by thescientist Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now