2

How would you go about finding a string constant that is not HTML-safe?

It appears the following searches for the individual characters.

var i = text.indexOf('»')
2
  • Can you give some examples of a non-safe string constant? Commented Jul 20, 2011 at 2:10
  • @Jcubed: My question includes an example of the type of character I had in mind. At any rate, the question has been asked and answered. Commented Jul 20, 2011 at 2:21

3 Answers 3

1

You'll first need to unescape the HTML in the pattern:

var i = text.indexOf(decodeHTML('»'));

function decodeHTML(s) { // e.g. using jQuery
    return $('<div>' + s + '</div>').text();
}
Sign up to request clarification or add additional context in comments.

Comments

0
var i = text.indexOf('\273')

would search for the actual character.

http://www.c-point.com/javascript_tutorial/special_characters.htm explains how to escape special characters in javascript.

Comments

0

Try looking at the html directly.

document.getElementById('search').innerHTML.indexOf('&raquo;')

1 Comment

It's not able to find that. The data is updated via AJAX. Perhaps the HTML contains the character directory without using &raquo;?

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.