javascript - jQuery add a class to an element if there is another element on the page -
i want hide div container when there no <h5>
in it. div container hide. when server pulls feeds other website, <h5>
add inside div container. div should show on page.
here simplify version of html structure without out <h5>
<div id="alert-feed"> <div class="webpart-title">title</div> <div class="webpart-body"> <div class="contianer"> <ul class="feedlist"> <li class="campusfeed"> <ul class="articlelist"></ul> </li> </ul> </div> </div> </div>
here html <h5>
<div id="alert-feed"> <div class="webpart-title">title</div> <div class="webpart-body"> <div class="contianer"> <ul class="feedlist"> <li class="campusfeed"> <ul class="articlelist"> <li> <a><h5 class="articletitle"></h5></a> </li> </ul> </li> </ul> </div> </div> </div>
so want hide #alert-feed
adding class no-alert
when there no <h5>
inside it. know done using hasclass
, addclass
, structure confusing me , can't it. me figure out how this?
try - needs run after have tried pull feeds website
var feed = $('#alert-feed'); // feed if (!feed.find('h5').length) { // check if doesn't contain h5 feed.addclass('no-alert'); // if doesn't, add class }
Comments
Post a Comment