Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can anyone give me an example to use attribute as a selector in jquery?

user-image
Question added by Deleted user
Date Posted: 2015/10/12
Mostafa Mohammed Naguib
by Mostafa Mohammed Naguib , Senior back-end developer , Egpay payment solution

you can always try something like

$('input[type=text]');

 

which will select all input text boxes

and you can even use the selector as a CSS selector 

input[type=text] {

text-align: right;

}

This selector to give wide range of using the 'data-' attribute as example; you could have a many divs that have same class but some of them share same status

 

<div data-status='opened'>Opened div</div>

<div data-status='closed'>closed div</div>

<div data-status=opened'>Opened div</div>

<div data-status='closed'>closed div</div>

 

so using 

$('div[data-status=closed]');

would select only the closed divs or the open ones

 

hope i could clear that out for you :)

have a great day

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.