1

I'm playing around with JS on the youtube-website (the trending page).

What i'm trying to do: Write all elements "ytd-video-renderer" with class "ytd-expanded-shelf-contents-renderer" into variable xyz.

My Code:

var xyz = $("ytd-video-renderer.ytd-expanded-shelf-contents-renderer")

Unfortunally this is my console-output:

<ytd-video-renderer class="style-scope ytd-expanded-shelf-contents-renderer">

i get only the first element from this site. If i'm using only vanilla JS

var xyz = document.querySelectorAll("ytd-video-renderer.ytd-expanded-shelf-contents-renderer")

I'll get all elements in an array. - fine..

But I want to use jQuery because I need to "scan" every element in this array for a certain childnode and find() will not work if I'm using querySelectorAll.

BTW: I'm using the console in Chrome and Firefox.

Bharata
  • 13,509
  • 6
  • 36
  • 50
  • What do you see in the console when you do `console.log(xyz.length)` – Rory McCrossan Jun 26 '18 at 10:17
  • 2
    `$` isn’t jQuery here. It’s an [alias for `document.querySelector`](https://stackoverflow.com/q/11778477/4642212) within the console. Use `$$`. – Sebastian Simon Jun 26 '18 at 10:19
  • only "undefined". – Chris Wiedenmaier Jun 26 '18 at 10:20
  • `var ytdExpSCR = Array.from(document.getElementById("grid-container").querySelectorAll(".ytd-expanded-shelf-contents-renderer"));` – zer00ne Jun 26 '18 at 10:20
  • @Xufox YOU ARE RIGHT! thanks man! I will repsonse you tip as the correct answer. thanks buddy – Chris Wiedenmaier Jun 26 '18 at 10:21
  • Possible duplicate of [$ Variable in Chrome?](https://stackoverflow.com/questions/11778477/variable-in-chrome) – Sebastian Simon Jun 26 '18 at 10:24
  • 1
    Yes @Xufox is right. Just adding ..`$$` is an alias for `document.querySelectorAll()` so you can get an array. – Muhammad Usman Jun 26 '18 at 10:25
  • @xufox I value your contribution to SO, yet I would like to invite you to study this guide as this is a place of learning and tolerance. [1]: https://stackoverflow.com/help/be-nice [2]: https://stackoverflow.blog/2018/04/26/stack-overflow-isnt-very-welcoming-its-time-for-that-to-change/ – James Wong Jun 26 '18 at 10:35
  • @Xufox see how you went on a long rant? You abuse the downvote system to your liking. Please read this: https://stackoverflow.com/help/be-nice – James Wong Jun 26 '18 at 10:39
  • @JamesWong I did not abuse anything. A misleading, inaccurate or incomplete answer is not useful. Answers that are not useful should be downvoted. That was not a rant. That was an explanation of my actions. – Sebastian Simon Jun 26 '18 at 10:42
  • @Xufox I updated my answer 3 times to your ultimate conclusion that "YouTube does not load jQuery" yet you still kept the downvote :) but it doesn't matter, I flagged your comment as *rude and abusive* it was marked as helpful. Seriously this will do you some good: https://stackoverflow.com/help/be-nice – James Wong Jun 26 '18 at 10:43
  • @JamesWong Note that comment flags get marked as helpful, not only because moderators removed them, but also when comments are self-deleted, which I did, because one of them became obsolete. – Sebastian Simon Jun 26 '18 at 11:20
  • @Xufox Chill man, be nice. – James Wong Jun 26 '18 at 11:24

1 Answers1

0

Since i'm working with the dev-tool console of chrome and firefox, $ is an alias for document.querySelector . I need to change $ to $$. Now it's working. Thanks to @Xufox for your help!

Here's @Xufox 's comment:

$ isn’t jQuery here. It’s an alias for document.querySelector within the console. Use $$