I need a jQuery function that'll go through paragraphs with the following structure:
<p>
<label>some label</label>
<input type="text" value=""/>
</p>
The function should use the label text as input value.
Thanks!
I need a jQuery function that'll go through paragraphs with the following structure:
<p>
<label>some label</label>
<input type="text" value=""/>
</p>
The function should use the label text as input value.
Thanks!
$("p > label") To parse the structures, then you can use html() to get the value, but that returns the first node's value... What do you want to do with the label text?
$('p > label + input').val(function() { return $(this).prev().text(); });
Example: http://jsfiddle.net/D392c/
You can do it using .val()
with a function, like this:
$("p input").val(function() { return $(this).prev().text(); });
$('p').each(function() {
$(this).children('input').val($(this).children('label').text());
});