bigpotato
bigpotato

Reputation: 27507

How to hide dynamic content using jQuery/javascript?

I'm currently using a service for autocompleting my search boxes. However, for all the autocompleted results that show up, there's always a <div> ad on the bottom following the <li>s. Something like this:

<ul>
<li class="menu-item""></li>
<li class="menu-item""></li>
<li class="menu-item""></li>
<div style="text-align:center;border-top:1px solid black;"></div>
<a href="http://www.ad.com" target="_blank">ad</a>
</ul>

However, this is loaded dynamically using JS so I don't know how I would write jQuery to hide() it. Is there a way I could dynamically hide it when someone does a search?

Upvotes: 0

Views: 556

Answers (2)

loxxy
loxxy

Reputation: 13151

If you are sure of the structure, you can always address it in jquery as

$("ul").find("a,div").hide()

Best would be of course css, as Kolink answered.

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

You could do something like this in your CSS:

ul>* {display:none}
ul>li {display:block}

After all, it is only valid for <ul> elements to have <li> children, so you should be able to hide everything else as invalid.

Upvotes: 2

Related Questions