Assume that we have the following code:
<span class="input-text">
<input type="search">
</span>
Is there any way, we could set the value
of that without having the ID of the element?
Assume that we have the following code:
<span class="input-text">
<input type="search">
</span>
Is there any way, we could set the value
of that without having the ID of the element?
- The question is little unclear to me . your saying set value of element by class name and you did not give a class to your input tag instead to span tag please be little more specific , what does that mean in your question ? input or span – niko Commented Jan 22, 2014 at 12:38
7 Answers
Reset to default 3Possible solutions are many. .val('your value')
is the method to set the input tag value
jQuery
With class referring to span element
$('.input-text').find('input').val('value');
$('.input-text input').val('value'); // descendent selector
$('.input-text > input').val('value'); // direct children selector
Without referring to span element
$('input[type=search]').val('value'); // attribute selector
Javascript
$('.input-text').find('input')[0].value = 'value'
Or If you want to over write the content inside the <span>
tag use
$('.input-text').html('content')
$('span.input-text').html('content')
You can do like this :-
$(".input-text").children().val('set any value you want to')
Use like this:
$('input[type="search"]').val("set your value");
You can use Attribute Equals Selector [name="value"]
$('input[type="search"]').val("Your Value");
or
$('.input-text input').val("you value");
DEMO
You should refer jQuery selectors. This would be more helpful to you.
try val()
or value
$('input[type="search"]').val("Your Value");
or
$('input[type="search"]').value = "Your Value"
Try this:
$(".className").val("your value");