0

Is there any ways inserting special html codes:

(      – —)

using .text()?

Following construction will not work:

$.text('&nbsp');

JSFiddle (if necessary): http://jsfiddle.net/7yR95/

1
  • 4
    text() sets the text content of the element, so no. Why not use html() instead? Commented Aug 5, 2014 at 8:57

2 Answers 2

2

use html() instead of text(), theres no way text() can make — to be a dash

check the fiddle for html()

$('.result').html('—');

http://jsfiddle.net/7yR95/1/

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

3 Comments

@Se0ng11- This is wrong answer OP wants answer using text()
@AmitAgrawal We cant insert that special character using text(), you should know what is diff b/w text() and html() in jquery
@Bala I know difference. You can also achieve using append but the question is - Can achieve using text
2

You can use '\xa0' for  :

.text('\xa0');

   ----> xa0

– ----> x96

— ----> x97

see more in ascii table

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.