Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (13.1k points)

I am writing a code where all persons’ names come from Facebook API. and it is showing in the lightbox. Now I want to implement search feature/ functionality using Javascript/JQuery. Can somebody help me with this?

 <div> <input type="text" id="search-criteria"/>

    <input type="button" id="search" value="search" onClick="tes();"/> </div>

<fieldset>

    <legend>Invite Facebook Friend</legend>

    <div class="fbbox">

    <img src="images/User.png" class="fbimg" />

    <div class="fix"><label for="check-2" class="left"> James </label></div>

    <input type="checkbox" name="fb" id="check-1" value="action" class="leftcx"/>

    </div>

    <div class="fbbox">

    <img src="images/User.png" class="fbimg" />

    <div class="fix"><label for="check-2" class="left">Alan </label></div>

    <input type="checkbox" name="fb" id="check-2" value="comedy" class="leftcx"/>

    </div>

    <div class="fbbox">

    <img src="images/User.png" class="fbimg" />

    <div class="fix"><label for="check-3" class="left"> Mathew </label></div>

    <input type="checkbox" name="fb" id="check-3" value="epic" class="leftcx"/>

    </div>

1 Answer

0 votes
by (7k points)

You can do like this:


$("#search-criteria").on("keyup", function() {

    var g = $(this).val();

    $(".fbbox .fix label").each( function() {

        var s = $(this).text();

        if (s.indexOf(g)!=-1) {

            $(this).parent().parent().show();

        }

        else {

            $(this).parent().parent().hide();

        }

    });

});​

Or in a better way:

$("#search-criteria").on("keyup", function() {

    var g = $(this).val().toLowerCase();

    $(".fbbox .fix label").each(function() {

        var s = $(this).text().toLowerCase();

        $(this).closest('.fbbox')[ s.indexOf(g) !== -1 ? 'show' : 'hide' ]();

    });

});​

Want to be a full stack developer? Check out the full stack developer course from Intellipaat. 

Related questions

0 votes
1 answer
0 votes
3 answers
0 votes
1 answer
0 votes
1 answer
asked Apr 7, 2021 in Java by dante07 (13.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...