开发者

Toggle attr value on click

I'm trying to toggle a attr val开发者_如何学运维ue (rel or href) on click.

$('#open').click(function () {
    $(this).text($(this).text() == 'View Project' ? 'Close' : 'View Project');
    $(this).attr('rel','#page');
    $('#view').slideToggle(550);
    return false;
});

I've got a text swap in there that's change out the text for a#open when toggled open/toggle close.

But I need to swap the rel or href from #view to #page when toggled open but then back to #view on the toggle close. I'm needing the swap of these as it's needed for using scrollTop.

Any help would be greatly appreciated!


Basically you're wanting to do the same thing to your rel attribute that you're doing to the text of the element.

$(this).attr('rel',$(this).attr('rel') == '#page' ? '#open' : '#page');

and I assume you want to use the current rel for the slide toggle

$($(this).attr('rel')).slideToggle(550);


not sure I understand completely, but have you considered using .toggle() in jquery in place of .click() and then use different functions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜