NZMAI NZMAI - 1 year ago 125
HTML Question

Hide a div if paragraph does not contain any text

I'm doing a project using Wikipedia API. Typing a word in seach bar displays a list of items. Like in the picture below.
Image one
When a user hover over "more" div an additional content is dispalyed below. like that.
Image two

However some items in blue color do not containany information, that is, empty. So i want for those items which do not contain any additional information do not show "more" div. So i have written a code. But unfortunately it does not work.

if ($('.list-container>div.titleDesc>p').is(':empty')) {

Cannot figure out what is wrong so will appreciate any help. If you need more information please refer to my project in Codepen.

Answer Source

jQuery :empty() is a selector; hence, it works on jQuery elements. So, you need to update this line:


With this line:


Here is a Working Demo, I have just updated this JS line, and add a container div element.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download