1

I have a simple HTML label input. By using the ajax request, I get back the HTML string which I want to put as that label's text. To do so, I try the following code:

$('#my-label').text($("<label class='someClass'>4.00 ABC</label> (13.26 DEF)"));

but nothing happens. How to cope with that ?

1
  • What part of the label.someClass do you want in #my-label? Do you want to wrap the labels? Commented Apr 11, 2013 at 16:33

1 Answer 1

4

Use .html()

$('#my-label').html("<label class='someClass'>4.00 ABC</label> (13.26 DEF)");

Although I'm not sure what #my-label is supposed to be in your case ..

Edit: If it is the id of the label itself as PRPGFerret suggested, a better approach would be:

$('#my-label').text('4.00 ABC').addClass('someClass');
Sign up to request clarification or add additional context in comments.

2 Comments

I would assume the ID of the label tag :P
is this someClass allready existing in your markup? so you could write $('label.someClass').text('4.00 ABC');

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.