0

I have some part numbers as a string.For example : partnumber = "a1;a2;a3"

Now I am displaying it using text() function like

$("#id").text("Part number(s) " + partnumber+ " is shown");

But I want to change the color of partnumber only and not the full text.

So I should get something like this :

Part number(s) (some color) a1;a2;a3 (some color) is shown. How to do this using jquery?

3 Answers 3

2

You have to wrap it in a span and use a class to define the extra styling:

$("#id").html('Part number(s) <span class="your_color_classname">' + partnumber+ '</span> is shown');

You have to use html() instead of text() because you are inserting html not plain text.

Sign up to request clarification or add additional context in comments.

Comments

0

You'll need to change your html a bit:

<div id="id">Part number(s) <span id="partnumbers"></span> is shown</div>

And then in jquery:

$("#partnumbers").html(partnumber);

This way you can style #partnumbers and #id separately through Css

Comments

0
$("#partnumbers").html("Part number(s) <span style='color:red'>" +partnumber+ "</span> is shown");

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.