Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery selector issue
    primarykey
    data
    text
    <p>I have a div which in jquery's document ready I append - using <code>$("#div id").append('html text')</code> syntax - with 10 or so more div child elements.</p> <p>once this is done I try to check the content of the child divs via <code>alert($(".classname"));</code> and it comes back with:</p> <pre><code>function(a){if(c.isFunction(a))return this.each(function(b){var d=c(this);d.text(a.call(this,b,d.text()))});if(typeof a!=="object"&amp;&amp;a!==w)return this.empty().append((this[0]&amp;&amp;this[0].ownerDocument||s).createTextNode(a));return c.text(this)} </code></pre> <p>I would have expected it to alert with the html contents of the child divs and not javascript?</p> <p>full script:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ // twitter api's base url var url="http://search.twitter.com/search.json?callback=?&amp;result_type=recent&amp;q="; // we'll store the search term here var query = "blah"; // get the json file $.getJSON(url+query,function(json){ // this is where we can loop through the results in the json object $.each(json.results,function(i,tweet){ // this is where we do what we want with each tweet $("#results").append('&lt;div class="tweetBox"&gt;&lt;span class="unseen"&gt;'+tweet.created_at+'&lt;/span&gt;&lt;div class="tweetImg"&gt;&lt;img src="'+tweet.profile_image_url+'" width="48" height="48" /&gt;&lt;a class="overbox" href="http://twitter.com/'+tweet.from_user+'/status/'+tweet.id+'"&gt;&lt;/a&gt;&lt;/div&gt;'+tweet.text+' ...said '+((new Date().getTime()/1000/60)-(new Date(tweet.created_at))/1000/60).toFixed(0)+' minutes ago&lt;/div&gt;'); }); }); $("#results").height(function(){return $(window).height()-204;}); alert($(".unseen").html()); }); &lt;/script&gt; &lt;div id="results"&gt;&lt;/div&gt; </code></pre> <p>update: definitely some kind of jquery/javascript race condition going on here, if I replace the alert with <code>setTimeout(function(){alert($(".unseen").html());},1000);</code> it returns the text expected. If I change the timeout pause to 1 millisecond it returns <code>null</code> once again.</p> <p>Not sure of a 'real' workaround for this other than sticking in the delay?</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.
    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