Reputation: 15404
I have a large string in a variable that includes a whole bunch of HTML tags.
I want to get the value of a hidden input field within the string and store it in its own var.
<input type="hidden" value="WantThis" />
Can anyone help me out at all?
Upvotes: 0
Views: 710
Reputation: 4423
Get the hidden input like so:
$(html).find("input[type=hidden]").val()
Upvotes: 1
Reputation: 224859
You can parse the HTML with jQuery to get the value:
var theValue = $(myString).find('input[name=something]').val();
I'm assuming the hidden field has a name. If it doesn't, you'll need to specify input[type=hidden]
and find it using its position relative to the rest of the content.
If your string does not already have a root element and the <input>
is not nested, you'll probably want to use $('<div>' + myString + '</div>')
instead.
Upvotes: 1
Reputation: 5781
Create an ID for the hidden input and call it like normal
<input type="hidden" value="WantThis" id="myInput" />
Then call it
var myval = $('#myInput').val();
Upvotes: 0