user1048676
user1048676

Reputation: 10066

Getting the value of a hidden input field is undefined

All, I have the following code:

$.infinitescroll.prototype.pageNumber = $("#pagenumber_" + selector).val();
alert($.infinitescroll.prototype.pageNumber);

The alert says undefined. Here is my HTML:

<input type="hidden" id="pagenumber_.category-dj" value="20">

When I do an alert like this:

alert("#pagenumber_" + selector);

These match, why is my val() coming up as undefined?

Upvotes: 0

Views: 1164

Answers (2)

nderscore
nderscore

Reputation: 4261

A period . indicates a class in a CSS selector. One option is use an attribute selector instead to select the element by ID.

$("[id='pagenumber_" + selector + "']").val();

Upvotes: 1

James Montagne
James Montagne

Reputation: 78740

You need to escape the . as this has a special meaning in a jquery selector. It needs to be \\..

Upvotes: 2

Related Questions