Found similar questions but nothing that covers exactly what I need. I kept it simple in my example and I want to use JQuery.
I have two classes. I want to hide the "filter" div if the "category" div is shown on page load. There are currently NO styles associated with either class. I believe I am pretty close but it doesn't work.
<script language="text/javascript">
if(!$(this).hasClass("category")){
$('filter').css('display', 'none');
}
</script>
<div class="category">By Category</div>
<div class="filter">By Custom Filter</div>
Thanks in advance!
Change the selector to
$('.filter')
Assuming by "shown on page load" you mean rendered and not the show/hide visibility.
jQuery
or just:
Use
.length
to test if an element is present.Use
.hide()
&.show()
to show and hide elements.And finally, you want the code to run only when the page has finished loading, so you want to wrap it all in
$(document).ready()
.So something like this should work best:
HTHs,
Charles