2

Hi I am trying to get all hidden fields on page with jQuery which have class name that I specify and have value of true. For this I am using following jQuery selector

$("input[class='EditModeStatus'][value='true']");

Here I want to get all hidden fields with class name "EditModeStatus" and have value of "true". This selector works fine in Mozilla and Chome but when I am testing it in IE8 it's not working. What will be issue in this?

Thanks

tutankhamun
  • 880
  • 2
  • 11
  • 21
CodeWarrior
  • 763
  • 3
  • 14
  • 33
  • 1
    can you share a html markup which is not working – Arun P Johny Aug 08 '14 at 09:43
  • 1
    If you have multiple classes assigned to those elements, you will need to use `$("input[class*='EditModeStatus'][value='true']");`, the asterisk indicates `contains` not `equals` (only), this is also assuming they have a `value` attribute. – SW4 Aug 08 '14 at 09:50
  • 2
    older IE has issues with getting any attribute where the property name is something else, for instance `getAttribute('class')` doesn't work in IE, but in all other browsers, but for some reason `getAttribute('className')` works in older IE, but not in other browsers, so I'm guessing that's the issue. Why not just do `$("input.EditModeStatus[value='true']");` instead – adeneo Aug 08 '14 at 09:51
  • Do you have a `DOCTYPE`? [This page](http://www.w3schools.com/cssref/sel_attribute_value.asp) says you need it – blgt Aug 08 '14 at 09:52
  • Mentioned jquery selector is not working. Html for hidden field is like this When edit mode is ON I assign value='true' indicating edit mode is ON and when done I assign value='false' indicating edit mode is OFF – CodeWarrior Aug 08 '14 at 09:52
  • 1
    you could look into this answer: http://stackoverflow.com/a/6732402/3244925 `$("input.EditModeStatus").filter(...)` – Nico O Aug 08 '14 at 09:59
  • Thank you all and @Nico O. By using $("input.EditModeStatus").filter(...) it's working. – CodeWarrior Aug 08 '14 at 10:15

1 Answers1

2

Thanks all for your valuable replies.

Instead of following selector

$("input[class='EditModeStatus'][value='true']")

I used this

var IsEditModeOn = $("input.EditModeStatus").filter(function () { return this.value == 'true' }).length > 0;

and it works in all browsers.

CodeWarrior
  • 763
  • 3
  • 14
  • 33