Jump to content

Using :contain to search div content


frazzlesnazzle
 Share

Recommended Posts

I have an FAQ page that contains a series of <div>s which are displayed/hidden based on navigation tabs on the side, and I am trying to install a search functionality using :contain to scan them for keywords but cannot get it working properly. What I have so far is :<script type="text/javascript">function searchFunction() { var searchTerm = document.searchBox.keyword.value;$(".searchable :contains('"+searchTerm+"')").css("style", "display:block");}</script><form name="searchBox">Keyword(s): <input type="text" name="keyword" /><input type="button" value="Search" onclick="searchFunction()"/></form><div class="searchable" id="softwareQuestion1" style="display:none">This is the first software question and answer.</div>What I want is for an input of "software" for example to cause any elements containing that word to be shown.Thanks

Link to comment
Share on other sites

How about using achors<a name="first"> something here </a><a name="second"> something else here </a>then faq.php#second will scrool to "something else here"Or you really need to show only one div and hide others?

Link to comment
Share on other sites

well, what happens instead? Are you getting any errors? edit:I'm confused why you are using jQuery for everything but getting the value, in which you use old form dot notation. Why not just jquery there as well?

var searchTerm = $('#keyword').val();...Keyword(s): <input type="text" name="keyword" id="keyword"/>

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...