Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Attribute selector in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 264
    Comment on it

    Attribute selector:

    We usually use either Class or ID  to find html elements in jQuery but we can also use attribute to find specific elements. Attribute selector is written inside square brackets [attribute].

    Some of the  common attributes mostly used are −

    • className
    • tagName
    • id
    • href
    • title
    • rel
    • src

    Example:

    <div class="main-blk">
    		<p>Sed ut perspiciatis <span title="legal">Legal</span> unde omnis</p>
    		<p>Sed ut perspiciatis unde omnis<span>justice</span> unde omnis</p>
    		<p>Sed ut perspiciatis unde omnis <span title="service">Services </span> unde omnis</p>
    		
    	</div>
    
    <script type="text/javascript">
    		$(function()
    		{
    		   $("[title]").css({"color":"red","border-bottom":"2px solid grey","margin":"10px 0px","padding":"0px 5px"});
    		});
    		
    		
    
    </script>

    In the above example we are using title attribute to apply style using jQuery. Similarly we can use other attributes to find html elements using jQuery.

    You can check above example output here: https://jsfiddle.net/bwzL83tc/4/

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: