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.

1

4 Answers 4

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Argh. Wasted 45 minutes before this. Going through all sorts of Jquery revision updates, scoping, etc. Sometimes human stupidity is infinite.
I've been burned so many times by this, and I never seem to learn.
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" 

Comments

0

You can try with this:

jQuery('a[id^="#buy-items"]').attr('id');

Comments

0

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

1 Comment

that is not wrong you can escape your special characters, or you can use attribute selectors with string values surrounded by quotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.