Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select element which doesn't has Id attribute?

I have two textarea and one of them has id attribute and other one doesn't has. Something like this:

<textarea> </textarea>
<textarea id = 'idname'> </textarea>

Now I need to select first textarea, How can I do that?

like image 520
stack Avatar asked Apr 07 '26 05:04

stack


2 Answers

You could combine the :not() pseudo-class and the [id] attribute selector in order to negate elements with an id attribute:

textarea:not([id]) {}
document.querySelectorAll('textarea:not([id])');
$('textarea:not([id])');

Basic Example:

textarea:not([id]) {
  width: 100%;
}
<textarea></textarea>
<textarea id='idname'></textarea>
like image 61
Josh Crozier Avatar answered Apr 09 '26 18:04

Josh Crozier


As you also don't mind a jQuery answer:

$('textarea:not([id])');

or

$('textarea').not('[id]');

Update:

For a specific name:

$('textarea[name="somename"]');
like image 38
Gone Coding Avatar answered Apr 09 '26 18:04

Gone Coding



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!