Friday, August 7, 2015

How to use Selector or attributes contains value in Jquery


In Jquery val or text conatins search ........
Select href attributes values starts with ,end with ,contains,not equal ,equal  values

$("a[href*='id=ABC']").addClass('class');


Contains
==========
*=will filter attributes that contain sin Anywhere
Example
--------
$('a[href*="?"]').each(function() {
    alert('Contains question mark');
});

Starts With
===========
^= will filter attributes that Starts with

Example
$("a[href^='#']").click(function() {
    alert('works');
});
will select any anchor whose href starts with a #

For attributes:
=================

= is exactly equal
!= is not equal
^= is starts with
$= is ends with
*= is contains
~= is contains word
|= is starts with prefix (i.e., |= "prefix" matches "prefix-...")

For Examples
=============
$('a[href$="ABC"]')...
$("#idtbl a[name*='value']").text()or hide()
$("#zz13_RootAspMenu li").find('a[href$=x]')



More Details :Selector documentation can be found at http://docs.jquery.com/Selectors 

No comments:

Post a Comment