ozz
ozz

Reputation: 5366

Uppercase tags in Internet Explorer 8

I have an HTML manipulation issue that manifests itself only in IE8.

I had recently written some javascript that analysed a tag and did something depending on what it was.

The piece of code assumed the tag was in lowercase.

if(value.indexOf('<input') == -1)

This failed under IE8 and I have to fix it.

Now I could and a second check as follows:

if(value.indexOf('<input') == -1 && value.indexOf('<INPUT') == -1)

This will catch both possibilities, but seems awfully messy.

Is there a better way to deal with this situation? Could JQuery deal with this?

"value" is an html string passed to my javascript function from JQGrid. Using IE8 the string is uppercase, using IE9, FF, Chrome, it is lowercase.

Upvotes: 0

Views: 1818

Answers (3)

Peter Pajchl
Peter Pajchl

Reputation: 2709

Depending on your situation obviously you could also use jquery .is() function to test for an element http://api.jquery.com/is/

for instance

$target.is("input")

Upvotes: 1

David Hedlund
David Hedlund

Reputation: 129812

Use

if(value.toLowerCase().indexOf('<input') == -1) { ... }

or

if(!/\<input/i.test(value)) { ... }

The latter being a regular expression with the ignore case flag set.

Upvotes: 2

nico
nico

Reputation: 51680

This should do the trick:

if(value.toLowerCase().indexOf('<input') == -1)

Upvotes: 3

Related Questions