0

I am working on a website that contains two elements with the same "id" (but different case) ie "freeshipping" versus "freeShipping". When I try to select the freeShipping element in JS, the browser returns the content of freeshipping instead. On my coworker's computer it works just fine.

Does anyone have any idea why it would act as case insensitive in this case? I've been looking online and all I can find is people complaining at other people saying "use the same case". However, no answer to my question about why the case sensitivity is not working.

<div id="freeshipping" style="display: none; padding: 15px;">
   Free Shipping on orders over $199!
</div>
<span id="freeShipping" class="stock">#freeShippingQualifierText#</span>

EDIT:

$freeShipping = $('#freeShipping');
$freeShipping.text('Free Shipping!');
Community
  • 1
  • 1
bia.migueis
  • 1,996
  • 2
  • 15
  • 23
  • 2
    Show your code where you are "trying to select freeShipping in JS it was returning the content of freeshipping" – Ian Mar 12 '13 at 17:00
  • 1
    This is browser dependent: [In the DOM are node ids case sensititve?](http://stackoverflow.com/questions/1236856/in-the-dom-are-node-ids-case-sensititve) – nicopico Mar 12 '13 at 17:01

1 Answers1

2

Having the same id is just asking for trouble. But if you really MUST do it, be context sensitive.

$("div#freeshipping").text();
$("span#freeShipping").text();

Should work, assuming the browser accepts the IDs.

Andrei Nemes
  • 3,062
  • 1
  • 16
  • 22