milandjukic88
milandjukic88

Reputation: 1115

How to get all input fields with particular attribute?

<input type="text" someCustomAttr="value"></input>

This code sometimes work sometimes not:

$fields = $('input[someCustomAttr="value"]','#contaners_id');

Is this ok?

Upvotes: 0

Views: 40

Answers (3)

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93223

It should work :

<input type="text" someCustomAttr="value" value="fdfgfdg"></input>


<div></div>

DEMO

If it isn't worked yet, Change Jquery lib version and Use one such as used by jsfiddle in this demo : http://jsfiddle.net/abdennour/UYTKr/

Upvotes: 0

Matthew Booth
Matthew Booth

Reputation: 71

If you want just the attribute and don't care about the value, then do:

$fields = $('input[data-custom]');

Additionally, if you want elements besides inputs that also have that attribute, then just do:

$fields = $('[data-custom]');

Upvotes: 0

Mooseman
Mooseman

Reputation: 18891

  1. Change someCustomAttr="value" to data-custom="value".
  2. Use $('input[data-custom="value"]);

Upvotes: 3

Related Questions