Jump to content

function with a function


jimfog

Recommended Posts

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 by jimfog
Link to comment
Share on other sites

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

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

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 by thescientist
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...