0

I have the following html:

HTML

<span id="plus one">Plus One</span>

jQuery

$("#plus one").hide();

The jQuery to hide the span doesn't work and I suspect it is because there is a space in the id name.

I cannot change the id name or use a class orname as an alternative. Is there anyone other way to deal with this? All feedback welcomed - thanks.

Homer_J
  • 3,277
  • 12
  • 45
  • 65
  • Try `$('#plus#one')` though I'm not sure if that'll work. – pstenstrm Jul 13 '14 at 16:58
  • html ids do not allow multiple values / spaces. however, classes allow multiple values. try then something like $('#plus-one.plus.one') will work and should illustrate an answer to your question – iphipps Jul 13 '14 at 17:00
  • 2
    start by using valid `ID`...space is not valid – charlietfl Jul 13 '14 at 17:00
  • http://stackoverflow.com/questions/596314/jquery-ids-with-spaces – Ivan Ivanov Jul 13 '14 at 17:00
  • This is indeed a duplicate - didn't find the 'dealing with a space' in my searches - happy for this to be closed. – Homer_J Jul 13 '14 at 17:03
  • @charlietfl - I couldn't agree more - however I'm dealing with inherited code that would require major work to overcome that issue. I appreciate this is a `dirty-fix`. – Homer_J Jul 13 '14 at 17:04

1 Answers1

6

Use attribute selector:

$("span[id='plus one']").hide();

or

$("#plus\\ one").hide(); // copied from below ref.

Ref: jQuery: dealing with a space in the id attribute

Community
  • 1
  • 1
Kiran
  • 20,167
  • 11
  • 67
  • 99