0

I have a line of code as follows:

$('#type').val(target).trigger('change');

It opens a new div(it was display none). I want to run a code after that div opens and locates at DOM. How ca I do that?

1
  • I'm guessing from your question that the div is shown in response to the change event. If the div was display: none and all you're doing is showing it, it's already in the DOM tree. It should appear near instantaneously, no need to wait. If my guess is incorrect, the question needs (much) more information. Commented Nov 29, 2011 at 13:34

2 Answers 2

2

You could pass a function to the event and execute it like so:

$('#type').val(target).trigger('change', function() {
//do something
});

//in your event
$('#type').change(function(event, func) {
       //do things
       if(func) {
          func();
       }
});
Sign up to request clarification or add additional context in comments.

Comments

0

You can create an event listener on that trigger just like you would any other native jQuery event.

//You can trigger it like you usually do or optionally pass in extra parameters in case you want your subscribed listeners to have access to that info
$('#type').val(target).trigger('change', param1, param2);

$('#type').live("change", function(event, param1, param2) {
       $("#myDiv").show();
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.