Reputation: 1183
I would like to be able to console.log the caption text from each paragraph on hover. The problem I am having is it is not outputting the correct caption text.
jQuery('.videogall-thumb').each(function () {
jQuery(this).hover(function () {
var name = jQuery('videogall-caption').html();
console.log(name);
});
});
<div class="videogall-thumb">
<p class="videogall-caption">Jon</p>
</div>
<div class="videogall-thumb">
<p class="videogall-caption">Bob</p>
</div>
<div class="videogall-thumb">
<p class="videogall-caption">Mark</p>
</div>
Upvotes: 0
Views: 331
Reputation: 258
jQuery('.videogall-thumb').each(function() {
jQuery(this).hover(function(){
var name = $('> .videogall-caption', this).html();
console.log(name);
});
});
Upvotes: 0
Reputation: 78650
jQuery('.videogall-thumb').mouseenter(function(){
var name = jQuery(this).find('.videogall-caption').text();
console.log(name);
});
The changes I made:
.
in your selector for videogall-caption
.mouseenter
instead of hover
. Hover will fire on enter and leave.each
at all, just call mouseenter
on the collection.find
to find the appropriate element instead of grabbing all of them (children
could be used instead if needed).text
to just get the text in case there are html elements within (maybe not a concern for you).Upvotes: 2