Relax Breath of Solution.Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist/ Interactive Designer

Just I wanted.. Do you?…

jQuery filters

Posted on September 4, 2011 | Comments Off on jQuery filters

Uses of JQuery filter

Some of the key uses are given below :

  • It is very similar to selector in fact we can say that it is a type of selector to enhance the functionality of selector.
  • We can select filter according to their position.
  • We can select filter according to tag name.
  • We can select filter according to child, last-child ,nth child ,only child.
  • We can select filter according to their visibility.
  • We can select filter according to sibling, adjacent, or descendant etc.

Use of jQuery attribute filters

Using jQuery attribute filters make it easy to select and modify particular attributes in your html DOM.

Given below is the demonstration how you can apply filters on attribute ,here we are using “a href ” attribute of html DOM :

  • Using it , you can hide all the link in your html page as : $(“a[href]”).toggle();.
  • But if you want to hide one link , you can do it as : $(“a[href=’http://www.ai.com/’]”).toggle();
  • If you want to hide the link which has “google” in href.
  • You can also hide the links which ends with “org” as $(“a[href$=’org’]”).toggle();
  • You can also hide the link which starts like ” http://doc ” as : $(“a[href^=’http://docs’]”).toggle();

eg:-

  <div></div>

  <div class="middle"></div>
  <div class="middle"></div>
  <div class="middle"></div>
  <div class="middle"></div>

  <div></div>
<script>

    $("div").css("background", "#c8ebcc")
            .filter(".middle")
            .css("border-color", "red");
</script>

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

Comments

Comments are closed.