AdBlock Detected

We provide high-quality source code for free. Please consider disabling your AdBlocker to support our work.

Buy me a Coffee

Saved Tutorials

No saved posts yet.

Press Enter to see all results

How to filter contents with jQuery?

By pushpam abhishek
Listen to this article
 How to filter contents with jQuery?

Jquery contains() Filter

  • Jquery contains() selectors get a content of a selected element which specified in the parameter.
  • This selector helps to extract content from an element.

$(document).ready(function () {
    $('button').click(function () {
        $('p:contains(select)').text());
    });
});  


  • Jquery :contains() selector select which paragraph contains a selected text.
  • This selection not depending on word spacing.

: Empty Filter

  • Jquery: empty selector select which element didn't have textual content or it to be empty.
$(document).ready(function () {
    $('button').click(function () {
        $('p:empty').text("hai"));
      });
});  

  • This example gets the paragraph that has empty and set a parameter value to an element.

:has() Filter

  • Jquery has() selector returns a boolean values only.
  • Which element have a matched content then only it returns true otherwise it returns false.

$(document).ready(function () {
    $('button').click(function () {
        $('p:has(span)').css("background","red"));
     });
});   


  • In this example show which p has a span that background only changes the mentioned color.

: parent Filter

  • A parent selector used to reach out to the child elements.
  • The referred parent get all it's child elements.
$(document).ready(function () {
    $('button').click(function () {
       $("td:parent").css("background-color", "orange");
    });
});     


  • In this example get the parent of td and push it into the jquery manipulation.

: visibility Filter

  • Jquery: visibility filters receive only a visible element. It refuses the hidden elements.

$(document).ready(function () {
    $('button').click(function () {
        $("p:visible").text() ;
        });
});
     

  • It notices the visible elements

: Hidden Filter

  • Invisible elements are to be select.

$(document).ready(function () {
    $('button').click(function () {
        $("p:hidden").show() ;
    });
});    


  • The hidden elements are only shown.

Share this post

pushpam abhishek

About pushpam abhishek

Pushpam Abhishek is a Software & web developer and designer who specializes in back-end as well as front-end development. If you'd like to connect with him, follow him on Twitter as @pushpambhshk

Comments