i want to add one Class to an image if it have alt attribute and one class to an image which doesnot have an alt attribute.
i tried this but its not working
if ($(img).hasAttr('alt'))
{
this.addClass("haveAlt");
}
i want to add one Class to an image if it have alt attribute and one class to an image which doesnot have an alt attribute.
i tried this but its not working
if ($(img).hasAttr('alt'))
{
this.addClass("haveAlt");
}
You can use attribute selector:
For the ones which don't have
alt
attribute, use:not
selector:As as side note to hande both cases in one function call, you can use: