Reputation: 15
<table border=2>
<tr>
<td class="here" one="lorem" two="ipsum"> click </td>
<td class="here" one="aaa" two="bbb"> click </td>
</tr>
</table>
$('.here').click(function(){
$(this).html($(this).attr('one'));
})
How can i modify this javascript for function toggle or other solution? I would like - if i click on TD then this show me attribute one, and if i next click then this show me attribute two, next one, next two etc
Upvotes: 0
Views: 72
Reputation: 2923
ocanal's answer works perfectly but I thought I'd add that this can also be done with toggle
which when given two functions will switch between them for each click:
$(".here").toggle(function() {
$(this).html($(this).attr('one'));
}, function() {
$(this).html($(this).attr('two'));
});
Upvotes: 1
Reputation: 13441
$('.here').click(function(){
if($(this).html() == $(this).attr('one'))
$(this).html($(this).attr('two'));
else
$(this).html($(this).attr('one'));
})
Upvotes: 1