Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Utilisateur supprimé
Date de publication: 2015/10/12
Mostafa Mohammed Naguib
par 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