To just get rid of the 'href' attribute:
$("#myLink[href='']").removeAttr('href');
For multiple targeting, such as the 'style' attribute:
$("#myDiv td, a, p, table, nav, header[style='']").removeAttr('style');
Thus, you will get rid of the attribute when it is empty, instead of deleting the entire element.
Full code example:
$('#myDiv table, tr, td, a, p').each(function() { if ($(this).attr('style') == '') { $(this).removeAttr('style'); } })
Kevin
source share