When trying to see why removeAttr doesn’t always seem to work I tried.
$("div#mydiv").css('height','200px');
$("table").removeAttr("border");
$("#mydiv").removeAttr("height");
The table borders attribute is removed OK but not the div height attribute. I need to use other suggested methods such as
$("#mydiv").css('height','auto')
to alter it but not actually remove it.
I would be interested to know what makes removeAttr not work in this scenario? There is no other css anywhere.
removeAttrrefers to the attributes of the tag. So, given:That span has three attributes, title, id, and style. removeAttr will let you remove any of these. But here’s the trick, while removeAttr will let you remove the style attribute, it can only remove both height and padding, it cannot edit either.
This:
results in:
css, on the other hand, lets you edit that style attribute directly.This:
results in:
Now, to remove just the height, you can pass an empty string to the second parameter.
This:
results in: