0

Im trying to change background color, text color, and text using jquery, however background color and text color is changing but text(string) not, Im using this code:

$('#page_'+(vector.length)).css("background", "orange");
$('#page_'+(vector.length)).css("color", "black");
$('#page_'+(vector.length)).css("text", "string");

I think the third line is writted bad, thank you.

2
  • 1
    Why are you trying to use .css() to alter an element's text? Commented Jan 26, 2014 at 16:44
  • In addition to Felix's correct answer, for performance reasons you may want to cache the jQuery object to a variable to avoid having to repeatedly query the DOM - "var element = $('#page_'+(vector.length)); element.css({ "background": "orange", "color": "black" }); element.text("string");" - see api.jquery.com/css/#css-properties for details on setting multiple styles simultaneously Commented Jan 26, 2014 at 18:10

1 Answer 1

2

You need to use text() instead of css() to change text inside your element:

$('#page_'+(vector.length)).text("string");
Sign up to request clarification or add additional context in comments.

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.