문제

This has been answered some times but mine is a different approach.

I want to toggle (via jQuery) a text on click. But I want to have this text defined in the html (because it is multilanguage and it depends in langs, more preciselly in Smarty variables) so the $(this).html(condition ? "Some" : "Other" ) doesn't work.

My actual approach is:

HTML

<a class="readmore" href="#content">
    <span class="text" rel="Menos">Más</span>
</a>

JS

$(".readmore").click(function(event) {
    var contentSelectAnt = $(this).find(".text").html();
    var contentSelect = $(this).attr("rel");
    $(this).find(".text").html(contentSelect);
    $(this).attr("rel",contentSelectAnt);
)};

But I don't quite like the redundancy of the code and the unapropiate use of the rel attribute. I am sure there is a more jquery style solution.

Thanks for reading.

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top