Jump to content
jimfog

function with a function

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

Share this post


Link to post
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">'); })

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...