开发者

How to test with jquery if an attribute equals ""

I have looked high and lo开发者_JS百科w for a solution and I have found many that come close to an answer but cannot find something that solves my exact problem.

I have jquery removing display: none; style attribute.

This sets the style attribute equal to style="" as there are no other styles set inside the style attribute.

How do i test and build an array of all the elements that have the style attribute set to style=""

NOTE the elements in question are part of a table with the id of #returnedTable

and the td elements look like <td style="" rel="22">

I am trying to return an array of the data contained in the rel attribute for each td element that has a style attribute set to style="". Note it will be mixed in with td elements that look like

<td style="display: none;" rel="24839">


You can get all elements with style set to "" like this:

var eles = $("*[style='']");

If you just want the rel attribute values, you can do:

var arr = $("*[style='']").map(function() {
    return $(this).attr("rel");
}).get();

Demo.


var rels = [];

$("#returnedTable td[style='']").each(function () {
  rels.push( $(this).attr("rel") );
});


Why not give those elements a particular class with jquery? You could easily build an array of their rel values then.

var rels = [];
$('#returnedTable tr td.myClass').each(function(){
   rels.push($(this).attr("rel"));
});


What about an attribute CSS selector?

[style=""]

Happy coding

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜