user3108268 user3108268 - 1 month ago 7
Javascript Question

Hide parent if child contains class

I followed this jQuery: Hide parent <td> if contains child <input> with specific class? but its not working in my code:

$(function() {
$(".video-list-item").filter(function() {
return $('span', this).hasClass('.view-count');
}).hide();
});


https://jsfiddle.net/xzeeuotL/

Answer

Two things to fix but you were close.

1) You did not include Jquery as a library for the JSFiddle

2) In the hasClass method you need to remove the . in the class name

$(function() {
$(".video-list-item").filter(function() {
     return $('span', this).hasClass('view-count');
}).hide();
});

Here is a working fiddle

https://jsfiddle.net/rn2jzpfc/