最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Convert jquery selectors to array - Stack Overflow

programmeradmin1浏览0评论

I need to be able to store the current selectors in the current viewport and then 10 seconds check if they are still in the users current viewport.

My solution for this was to store the selectors in an array and then in 10 seconds compare the old selectors against the new and see if any match. If they do... do something.

So i believe using .each and build the array, unless somebody has a more elegant solution to this?

$('.gridContainers:in-viewport')

This will return a standard selectors.

I need to be able to store the current selectors in the current viewport and then 10 seconds check if they are still in the users current viewport.

My solution for this was to store the selectors in an array and then in 10 seconds compare the old selectors against the new and see if any match. If they do... do something.

So i believe using .each and build the array, unless somebody has a more elegant solution to this?

$('.gridContainers:in-viewport')

This will return a standard selectors.

Share Improve this question edited Sep 10, 2012 at 15:45 Jamie Hutber asked Sep 10, 2012 at 15:37 Jamie HutberJamie Hutber 28.1k54 gold badges192 silver badges311 bronze badges 6
  • I don't get it. Can you elaborate that more in detail ? – jAndy Commented Sep 10, 2012 at 15:39
  • you're going to have to post some markup and some javascript so we can get an idea of what you're doing – jackwanders Commented Sep 10, 2012 at 15:39
  • 1 What have you tried? – zzzzBov Commented Sep 10, 2012 at 15:39
  • If I am understanding your question, their likely is a better way to handle the situation, but the way you are handling sounds fine to. No way to say for sure without a code sample. Please post some examples if the code you are using. – BishopZ Commented Sep 10, 2012 at 15:44
  • $(selector) always returns an array. – BishopZ Commented Sep 10, 2012 at 15:48
 |  Show 1 more comment

3 Answers 3

Reset to default 17

Calling $(selector) returns an array-like jQuery object, not an actual JavaScript array, though for the purposes of what they're trying to do converting it to an actual array may be unnecessary.

This is how one would turn a selector into an native Javascript array.

$(selector).toArray()

Jquery.toArray()

With ES6 :

Array.from($(selector)); // return JS array 

Try Out FIND method as Below:

$('element').find('selection');

This will give all selected elements to Array. Hope this helps

发布评论

评论列表(0)

  1. 暂无评论