weilin8
weilin8

Reputation: 2975

JQuery - Get value out of an input field inside hidden div

Will $('#some-field').val() return "something" or empty string? I assume it would return the value regardless if the div is visible or not. But I have been getting empty string. Any idea?

<div style="display:none;">
    <form>
        <input id="some-field" type="text" value="something" />
    </form>
</div>

Upvotes: 3

Views: 10086

Answers (2)

Marcus Recck
Marcus Recck

Reputation: 5063

It will return something. Visibility doesn't play a factor into retrieving values since it stills exist in the DOM.

Upvotes: 4

thecodeparadox
thecodeparadox

Reputation: 87073

Try this:

$('div:hidden #some-field').val();

DEMO

Even $('#some-field').val(); will work also, because visibility doesn't effect, if the element belong to DOM.

DEMO

Upvotes: 4

Related Questions