1

Simple line of code:

var page=jQuery("#buy-items-button").attr('id');

Problem is that page is undefined. Relevant portion of html

<li><a id='#buy-items-button' href="#buy-items" data-page="buy-items" class="section-button">Buy Items</a></li>

console.log(jQuery("#buy-items-button")) shows:

[context: document, selector: "#buy-items-button", jquery: "1.9.1", constructor: function, init: function…]
context: document
selector: "#buy-items-button"
__proto__: Object[0]

Driving me crazy as having been using jQuery for long and never faced issues on such trivial calls.

workwise
  • 820
  • 15
  • 26

4 Answers4

4

You need to remove # from id value of your anchor:

<li><a id='buy-items-button' href="#buy-items" data-page="buy-items" class="section-button">Buy Items</a></li>
Felix
  • 36,929
  • 7
  • 39
  • 54
  • Argh. Wasted 45 minutes before this. Going through all sorts of Jquery revision updates, scoping, etc. Sometimes human stupidity is infinite. – workwise Apr 30 '14 at 07:52
  • I've been burned so many times by this, and I never seem to learn. – blabus Apr 30 '14 at 08:47
0

Your HTML is wrong (remove # from id attribute):

<a id='#buy-items-button' href="#buy-items" 

should be

<a id='buy-items-button' href="#buy-items" 
Snake Eyes
  • 14,643
  • 31
  • 97
  • 188
0

You can try with this:

jQuery('a[id^="#buy-items"]').attr('id');
Jai
  • 71,335
  • 12
  • 70
  • 93
0

The id attribute in your HTML is wrong. Remove the pound sign.

  • 1
    that is not wrong you can escape your special characters, or you can use attribute selectors with string values surrounded by quotes. – Jai Apr 30 '14 at 08:02