Reputation: 1451
I'd like to access an input
inside a specific div
. I have this html :
<div id="'.str_replace(' ','',$systeme_culture['nom_plante']).'">
<table class="table">
<th>
<tr colspan="2">
<label>Nom : </label>
<input id="nom_itk" value="test">
</tr>
</th>
</table>
</div>'
I want to access the id nom_itk
inside the global div but I don't know how to do. I tried with .find()
but it doesn't work.
My js is :
$('#'+nom_culture).find('#nom_itk').html("test");
The global div is called with the variable nom_culture
in js.
Thanks in advance !
Upvotes: 0
Views: 84
Reputation: 1912
Below script will give you nom_itk value test
$('#'+nom_culture).find('#nom_itk').val();
and below will provide you object array
$('#'+nom_culture).find('#nom_itk').val('test');
$('#'+nom_culture).find('#nom_itk').html('test');
Upvotes: 0
Reputation: 1522
The problem is that you're trying to access an input element, which has no content (so you can't change it with .html()
), but a value.
Assuming the nom_culture
variable finds the right element (a parent of #nom_itk
), this will do what you want:
$('#'+nom_culture).find('#nom_itk').val('test');
Upvotes: 0
Reputation: 39413
The problem with your code it's that you are using html()
instead on val()
$('#'+nom_culture).find('#nom_itk').val("test");
To your question you can also use
$('#'+nom_culture + " #nom_itk").val("test");
(a space between the two) to select elements inside other elements
Upvotes: 1