I want to change a text within a p-tag when I click a link that is actually within the same p-tag.
Example:
var isMail = 0;
$('.switchto').click(function(evt) {
evt.preventDefault();
if(isMail == 0) {
$(this).parent().html("oder doch lieber einen <a href='#' class='switchto'>Facebook Freund</a>");
isMail = 1;
} else {
$(this).parent().html("oder lieber <a href='#' class='switchto'>E-Mailadresse eingeben</a>");
isMail = 0;
}
});
HTML:
<p>oder lieber <a href="#" class="switchto">E-Mailadresse eingeben</a></p>
Why is this not working correctly? Am I missing something? Is there an easier way to do this? Thanks!