[英]Selecting an element by a class using javascript or jQuery
I have the following html snippit; 我有以下html代码段;
<input name='first' class="foo" />
<input name='second' class="foo bar" />
<input name='third' class="foo" />
I want to set the value of a specific element, but i'm unable to select the right one. 我想设置特定元素的值,但是我无法选择正确的元素。 This is whar i've tried:
这是我尝试过的:
jQuery('.bar').val('selected');
Seems to be working fine, make sure you are running on dom ready. 似乎工作正常,请确保您正在准备运行dom。
$(function() {
$('.bar').val('selected');
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.