Reputation: 2846
I am trying to loop through my form inputs to check if the style
attribute exists. I feel like I am very close to having the correct code, but something is off. I know there are only 2 inputs that have the style
attribute, however, my code is detecting as if all 9 form elements have the style
attribute attached.
Here is my code:
$("#form-builder-wrapper input").each(function() {
var styleAttr = $("#form-builder-wrapper input").attr('style');
if (typeof styleAttr !== typeof undefined && styleAttr !== false) {
alert('Has style attribute');
}
});
Upvotes: 1
Views: 1373
Reputation: 847
You can use .is()
$("#form-builder-wrapper input").each(function(index, element) {
if ($(element).is('[style]')) {
alert('Has style attribute');
}
});
Upvotes: 0
Reputation: 337560
You can use the attribute selector to achieve this:
$("#form-builder-wrapper input[style]").each(function() {
alert('Has style attribute');
});
Upvotes: 2