Reputation: 679
I am trying to use a JQuery selector to select the title of a YouTube video. The HTML is as follows:
<div class="ytp-title-text">
<a class="ytp-title-link yt-uix-sessionlink"
tabindex="13"
target="_blank"
data-sessionlink="feature=player-title"
href="https://www.youtube.com/watch?v=aKVXR7tIa2k">More To Play For</a>
</div>
My code is
$('.ytp-title-link.yt-uix-sessionlink').text('a');
My result is "".
I expect the outcome to be: 'More to Play'
I am simply writing this code in the console of the latest Chrome browser in the hope it prints out 'More to Play'. However, it is not working. The same approach to other classes works with the web page I am working with.
But, I'm having problems with this YouTube snippet. Any help would be appreciated.
Upvotes: 0
Views: 243
Reputation: 9593
You have a space instead of a class selctor. Should be:
$('.ytp-title-link.yt-uix-sessionlink').text('a');
This is just going to change the anchor to have text of "a". If you want to grab (not change) the text, you just want:
$('.ytp-title-link.yt-uix-sessionlink').text();
Example here: JS Fiddle
Upvotes: 2