user472285
user472285

Reputation: 2674

add alt attribute to href depending on the class

the default state is:

<a  href="./" class="dynamic dynamic-children menu-item"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>

so if class = rfr-opened add alt="open"

<a alt="open" href="./" class="dynamic dynamic-children menu-item rfr-opened"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>

so if class doesn't have rfr-opened add alt="close"

<a alt="closed" href="./" class="dynamic dynamic-children menu-item"><span class="additional-background"><span class="menu-item-text">Présentation</span></span></a>

Upvotes: 2

Views: 1312

Answers (5)

user472285
user472285

Reputation: 2674

this works for me

jQuery("#rfr-topnav a").click(function () {
$('#rfr-topnav a').attr('title', 'closed');
$('#rfr-topnav a.rfr-opened').attr('title', 'open');
  });

Upvotes: 0

Allen Tellez
Allen Tellez

Reputation: 1211

I think something along the lines of . . .

$('a.menu-item')each(function() {

    if($(this).hasClass('rfr-opened')) {

        $(this).attr('alt', 'open');

    } else {

        $(this).attr('alt', 'closed');
    }
});

Upvotes: 0

Billy Moon
Billy Moon

Reputation: 58531

Tried and tested: http://jsfiddle.net/eMagu/ (I used inspector to check the alt value)

jQuery one liner...

// set all menu items to closed, then filter just the open class and set to open
$('.menu-item').attr('alt','closed').filter('.rfr-opened').attr('alt','open')

Upvotes: 1

Rusty Fausak
Rusty Fausak

Reputation: 7525

This should help:

$('.menu-item').each(function () {
    if ($(this).hasClass('rtf-opened')) $(this).attr('alt', 'open');
    else $(this).attr('alt', 'closed');
});

Upvotes: 0

mellamokb
mellamokb

Reputation: 56769

Something like this?

$('a').attr('alt', 'closed');
$('a.rfr-opened').attr('alt', 'open');

Demonstration: http://jsfiddle.net/9xLYV/

Upvotes: 3

Related Questions