Skip to content Skip to sidebar Skip to footer

Set The Value Of Element By Classname, Without Having The Element's Id

Assume that we have the following code: Is there any way, we could set the value of that without havi

Solution 1:

Possible solutions are many. .val('your value') is the method to set the input tag value

jQuery

Withclassreferring to span element
$('.input-text').find('input').val('value');
$('.input-text input').val('value'); // descendent selector
$('.input-text > input').val('value'); // direct children selectorWithout 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')

Solution 2:

You can do like this :-

$(".input-text").children().val('set any value you want to')

Solution 3:

Use like this:

$('input[type="search"]').val("set your value");

Solution 4:

You can use Attribute Equals Selector [name="value"]

$('input[type="search"]').val("Your Value");

or

$('.input-text input').val("you value");

DEMO

Solution 5:

You should refer jQuery selectors. This would be more helpful to you.

Post a Comment for "Set The Value Of Element By Classname, Without Having The Element's Id"