1

Need replace Read More... and Read Less... with images, buttons.

$("a", $(this).parent()).text($(this).is(':visible') ? 'Read More...' : 'Read Less...');

I tried

$("a", $(this).parent()).text($(this).is(':visible') ? '<img src=images/testeon.jpg>' : '<img src=images/testeoff.jpg>');

But it shows the src url

2 Answers 2

2

Try;

$("a", $(this).parent()).html($(this).is(':visible') ? '<img src="images/testeon.jpg">' : '<img src="images/testeoff.jpg">');
Sign up to request clarification or add additional context in comments.

3 Comments

String attributes without quotes are invalid HTML.
Why not change it so you only use the ternary operator on the image path rather than the full img element?
You're welcomw @Ricardo :)
0

You could set a container around of what you want to replace, then just replace its content with jQuery's .html() function

Here is an example

HTML:

<a id="myLink" href="javascript:insertImage();">read more..</a>

JS:

function insertImage()
{
    $("#myLink").html("<img src='http://3.bp.blogspot.com/--Fh64MyRDt0/T3XxC6ZVirI/AAAAAAAAJPo/WqHgsEZ7M8Q/s1600/image.php.jpg' />");
}

This will replace the content of the link ("read more..") with the given image tag.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.