-1
window.addEventListener('load', function(){
    var $frame = $('.feature');
});

$frame value some times showing with

0:div.popular-custom.frame.feature   context:document   length:1   prevObject:jQuery.fn.init[1]   selector:".feature" 
__proto__:Object[0];

but some times it is coming as

context:document   length:1   prevObject:jQuery.fn.init[1]  selector:".feature"  __proto__:Object[0]

Why am getting like this? I need to get always 0:div.popular-custom.frame.feature what do I have to do?

  • Can you show your HTML ? Do you have feature class on an element what which don't need to have this class ? – François Dupont Apr 11 '16 at 10:12
  • When evere name Croatians Featured_Tests feature class will add – Shaik Saidavali Apr 11 '16 at 10:14
  • Length equals 1 suggests they are equivalent. So what is your issue??? How do you 'show' result??? – A. Wolff Apr 11 '16 at 10:15
  • jQuery object corresponding to this div ( 0:div.popular-custom.frame.feature ) is not coming always?? – Shaik Saidavali Apr 11 '16 at 10:20
  • Why is that matter? It is just object representation in console (i guess), so again, what is your issue??? In your second example, you have lenght 1. Is it just bad code posting or what? Do you have 'sometimes' lenght 0 or what??? – A. Wolff Apr 11 '16 at 10:23
  • am applying sly slider in jQuery for this object ($frame.sly({ options }); ) when the object contains 0:div.popular-custom.frame.feature it is applying correctly when it is not their it is showing default behavior.. – Shaik Saidavali Apr 11 '16 at 10:27
  • We need to know how this element is added to the DOM. Dynamically??? Ajax request? – A. Wolff Apr 11 '16 at 10:29

1 Answers1

1

Try to use jquery ready if you are playing with jquery object.

<div class="feature">Hi</div>

window.addEventListener('load', function(){
    alert('load');
    var $frame = $('.feature');
  alert($frame.attr('class'));
});

$(function(){
 alert('jquery ready');
  var $frame = $('.feature');
  alert($frame.attr('class'));
});

JsFiddle : http://jsfiddle.net/5sfacr0b/

Nikhil Maheshwari
  • 2,148
  • 17
  • 23
  • If window load event doesn't work, why jQuery document ready would work? – A. Wolff Apr 11 '16 at 10:24
  • window.onload is the built-in Javascript event, but as its implementation had subtle quirks across browsers (FF/IE6/IE8/Opera), jQuery provides document.ready, which abstracts those away, and fires as soon as the page's DOM is ready (doesn't wait for images etc.). read http://stackoverflow.com/questions/3698200/window-onload-vs-document-ready – Nikhil Maheshwari Apr 11 '16 at 10:31
  • Yes i know but how an event fired before an other one would help in this case? That was my question :) – A. Wolff Apr 11 '16 at 10:32
  • The jQuery code would fire on document ready, not on load. Read more about this @ https://css-tricks.com/forums/topic/window-addeventlistener-load-vs-jquery/ – Nikhil Maheshwari Apr 11 '16 at 10:43