Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery selector for an element without any attribute

Tags:

html

jquery

css

I want to select an/all element which doesn't have any attribute associated with it.is there any way to select particular element without considering what attributes other paragraphs tags contain?

For example:

<p class="a" id="para1">This is paragraph 1</p>
<p id="para2" class="a b c d e f" >This is paragraph 2</p>
......
......
<p>This is paragraph 3</p> <!-- select this p without attribute -->
<div>
  <p class="inside-div" id="para5">This is paragraph</p>
</div> <!-- select this div without attribute-->
like image 842
Faisal Naseer Avatar asked Jan 31 '26 13:01

Faisal Naseer


1 Answers

You can use attributes collection of html element to find out if there is any attribute.

Demo

ps = $('p').filter(function(){
   return this.attributes.length == 0;
});
like image 122
Adil Avatar answered Feb 03 '26 05:02

Adil