Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI Tabs "Select" Event Being Overridden by "Click" Event -- Uncaught TypeError
    primarykey
    data
    text
    <p>I'm having some trouble selecting a tab programmatically. My tabs are loading inside a Fancybox dialog window, which is launched on click of a link. Basically, I want to perform certain actions any time a tab is selected, and also select a specific tab when a link is clicked.</p> <p>I am initializing jQuery UI Tabs with the <code>select</code> event like so:</p> <pre><code>$('#tabs').tabs({ select: function(event, ui) { // edit: here is the issue var activePanel = '.ui-tabs-panel:visible '; // grab value of a form input var text = $(activePanel + 'someElement').val(); // check its length if ( text.length &gt; 0 ) { // do stuff } } }) </code></pre> <p>Later on in my JS file I have the following:</p> <pre><code>$(document).on('click', 'a.edit', function() { if($category == 'book') { // load the tab specific to the 'book' category $('#tabs').tabs({ selected: 3 }); } }) </code></pre> <p>When I click the <code>a.edit</code> link for an item in the "book" category, my console throws this error:</p> <pre><code>Uncaught TypeError: Cannot read property 'length' of undefined </code></pre> <p>Then, instead of the tabs loading in the Fancybox, nothing happens. This error is <em>not</em> thrown when I click the link for items that are not in the book category. Thus, two things are painfully evident:</p> <ol> <li>I am a n00b</li> <li>My <code>select</code> event is apparently getting overridden by the click event, so <code>text</code> is not set</li> </ol> <p>I've tried setting a default for <code>text</code> at the top of my JS file but that doesn't work. My question, then, is:</p> <p><strong>What is the correct way to initialize UI Tabs with a select event, while also being able to programmatically select a tab with a click event?</strong></p> <p>Or, more concisely,</p> <p><strong>Why am I getting that damn error?</strong></p> <p><em>Edit: I amended my first code block above to include code that I discovered was relevant to my problem. See my answer below for a fuller explanation.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload