0

I've got a list of spans, containing numbers. I know how to extract numbers from span, that's easy, but one of my span is ½ character entity.

if ($(".XT_Active").html().text() === "½") {
   //Do stuff
}

if ($(".XT_Active").text() === "½") {
   //Do stuff
}

I need it to evaluate to true. Neither of these work.

Any tips?

SOLUTION

I moved this to a different, more appropriate function. The above evaluated before the class XT_Active could be given.

It's all good now. Thanks again everyone!

C_K
  • 1,243
  • 4
  • 18
  • 29

2 Answers2

1

It seems to work for me. Perhaps you have whitespace in your span.

http://jsfiddle.net/YL5Aj/

If that's not the issue you could try encoding the html entities using this technique

HTML-encoding lost when attribute read from input field

http://jsfiddle.net/gZuab/

Community
  • 1
  • 1
Matt Esch
  • 22,661
  • 8
  • 53
  • 51
0

Hiya Jason Simple demo here: http://jsfiddle.net/Y9dBG/

Hope this helps the example below is very basic as you i.e. replica of what you were trying. :)

Helpful link: (incase you want to use regex) Decimal or numeric values in regular expression validation

Quote (If you will use regex the link above should be helpful and quoting from above link :) But that should be only in case if you are looking to implement regex.

Rest hope this helps you, cheers!

Further update to handle commas and full stops

If you want to allow a . between groups of digits and a , between the integral and the fractional parts then try:

^[1-9]\d{0,2}(.\d{3})*(,\d+)?$

Jquery COde

alert('html value ==>' + $(".XT_Active").html().toString() );
alert('comparision ==>' + ($(".XT_Active").html().toString() == "½"));

if ($(".XT_Active").text() == "½") {
   // alert('foo ====' + $(".XT_Active").text());
   //Do stuff
}

if ($(".XT_Active").text() == "½") {
    alert('Yay I am inside the if condition' + $(".XT_Active").text());
   //Do stuff
}

HTML

<!-- <div class="XT_Active"> &frac12;</div> <br /> -->

<span class="XT_Active">½</span> <br />​
Community
  • 1
  • 1
Tats_innit
  • 33,991
  • 10
  • 71
  • 77