jquery - if div is empty, hide a different div element -


i have blog posts page "read more/read less" toggle button each post.

i hide "a.wpex-link" if ".wpex_div p" empty. problem needs select parent/closest link since posts have same class.

<a onclick="wpex_toggle(548787318, 'read more', 'read less'); return false;" class="wpex-link" href="#" target="_blank">read less</a> <div class="wpex_div" id="wpex548787318" style="display: block;">     <div class="sidebar-content"></div>     <p></p> </div> 

$('.wpex_div:has(p:empty)').prev('.wpex-link').hide(); 

$('.wpex_div:has(p:empty)').prev('.wpex-link').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <a onclick="wpex_toggle(548787318, 'read more', 'read less'); return false;" class="wpex-link" href="#" target="_blank">read less</a>  <div class="wpex_div" id="wpex548787318" style="display: block;">      <div class="sidebar-content">the p element empty. why 'read less' anchor not displaying</div>      <p></p>  </div>


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -