Take the 2-minute tour ×

I need to make a search by using jquery, I have an :
input text with this id idTextSearch:

<input id="idTextSearch" name="name" type="text" style="width:70%;"  >

input button with this id idButtonSearch:

<input id="idButtonSearch" type="button" value="Search" onclick="searching()" class="alt_btn">

and a <ul class="toggle" id="idUl"> with different <li value="thisIsAValue">

Now, I need to create my searching(), this function will hide all elements field different to $("#idTextSearch").val() and show only one field with the same value of this input text.

share|improve this question
really not clear what you're trying to do. Consider providing a block of HTML (rather than little snippets) and describing what you want to happen. Would be useful for you to put an example up on jsfiddle.net –  Jamiec Jan 9 '13 at 14:52
Post your JS and we'll help you out –  danronmoon Jan 9 '13 at 14:52
add comment

2 Answers

up vote 4 down vote accepted

Next time, please post what you've tried to do to solve the problem. In this case I'll give you the answer because it's simple, but we're here to help you, not to write all your code for you.

Note that the value attribute technically doesn't exist on the li element, you should prefix it with data. Eg:

<li data-value="thisIsAValue">

And the javascript/jQuery:

$('#idButtonSearch').on('click', function(e) {

    $('#idUl li').hide().each(function() {
        if ( $(this).data('value') === $('#idTextSearch').val() ) {
share|improve this answer
add comment
function searching() {
    var val = $('#idTextSearch').val();
    $('#idUl li').each(function() {
        var v = $(this).prop('value');
        if(v == val) {
        } else {
share|improve this answer
add comment

Your Answer


