0

Here's my problem.

I have 2 Tabs. First tab I have a button and in the second tab I have a select.

When I click the button with the id="select-" I want to trigger the change on $('#selector'). My problem is that the selector still doesn't exist (when I click the tab-content is not loaded yet.

So instead of click I wanted something like when tab-content loads or when tab is active. Any help?

//when select is clicked update parameters on load
$('[id^="select-"]').click(function () {
    $('#selector').trigger('change');
});

Edit: no it's not duplicate...

sdada
  • 41
  • 5
  • Possible duplicate of [Event binding on dynamically created elements?](https://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – fen1x Nov 16 '17 at 15:02
  • @sdada It isn't duplicate. Why do you use such language? – Praveen Kumar Purushothaman Nov 16 '17 at 15:04
  • Because I'm tired of people locking my posts with duplicates that have nothing to do with my problem. – sdada Nov 16 '17 at 15:07
  • "When the tab-content loads or when tab is active" - how are you creating your tabs? There should be an event when they are made active at least, if they're you're own tabs, then just raise an event. – freedomn-m Nov 16 '17 at 15:07
  • @fen1x It *might* be a duplicate, just not a duplicate of the suggested event binding on dynamically created elements. – freedomn-m Nov 16 '17 at 15:08
  • That tab content is there but it's not displayed until I click on the button. So i'm guessing until the selector is loaded the id doesn't exist and I get undefined... – sdada Nov 16 '17 at 15:09
  • Then you'll have to "queue" up the calls. On the click, check if the element exists, if not add it to a queue of things to do when it does exist. When you create the element, check the queue and action everything. If it's just a simple case of 'active this' then no need for a queue as a simple flag will suffice. They key being you check this when you do finally load the element that it will effect. – freedomn-m Nov 17 '17 at 09:17

0 Answers0