I'm trying to use jQuery to add some css to elements, but only if they have a certain attribute.
The reason why I'm not using just css is because the content for the site is too vast to go through and add classes to all the elements I want to style.
The jQuery code I'm using is this:
if ($('.body_text a').attr('name')) {
$(this).css({
'display': 'inline-block',
'position': 'relative',
'top': '-200px',
'visibility': 'hidden'
})
}
But this doesn't seem to be working. If I put an alert inside the if statement the alert works. Am I doing something wrong?
$('.body_text a[name]')