Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery .load preventing .hide and .show from working?
    primarykey
    data
    text
    <p>So I'm running into a weird issue with jQuery. Basically I have two elements on a page – a div that's getting a page fragment loaded into a child div via .load() (#optionOne in the example below) and another div that has static content (#optionTwo). Whenever a function gets called (every 10 seconds or so), it randomly selects one or the other to show() or hide(). Here's the javascript:</p> <pre><code> var editableOrSocial = Math.floor(Math.random()*2); if (editableOrSocial == 0) { $j('#optionTwo').hide(); $j('#optionOne').show(); $j('.thecontent').load('http://www.example.com/ .post-content', function() { }); } else { console.log('else called!'); $j('#optionOne').hide(); $j('#optionTwo').show(); } </code></pre> <p>Now this works perfectly if I remove the .load(). It will switch back and forth, show and hide each div appropriately. However as soon as I add the .load() in, it gets "stuck" on that option. Even if the else gets called, it doesn't actually show or hide either div (hence the little debugging "else called!" message in there... I wanted to make sure it worked).</p> <p>Anyone run into this issue before? Is .load() somehow overriding stuff? I'm extremely confused.</p> <p>EDIT: Nevermind, just figured it out right after I posted this. Changing this: </p> <pre><code> $j('.thecontent').load('http://www.example.com/ .post-content', function() { }); </code></pre> <p>to this</p> <pre><code> $j('#optionOne .thecontent').load('http://www.example.com/ .post-content', function() { }); </code></pre> <p>fixed it. However I'd still be interested in understanding why this happened. I'm guessing it maybe had something to do with load triggering a display state?</p>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    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