admin管理员组文章数量:1390775
I have a list of values in a drop down style select box e.g.
<select id="places">
<option>Italy</option>
<option>France</option>
<option>Germany</option>
<option>Spain</option>
</select>
I also have the same list of values in a div on my page e.g.
<div>
<span>Italy</span>
<span>France</span>
<span>Germany</span>
<span>Spain</span>
</div>
Using JQuery, I want to have it so - when a value in the dropdown is selected, the equivalent option in the div is briefly highlighted.
I've been struggling with the jQuery highlight plugin, but I believe the quicker way may be to use the highlight class of JjQuery UI. Apologies in advance for being a noob :)
I have a list of values in a drop down style select box e.g.
<select id="places">
<option>Italy</option>
<option>France</option>
<option>Germany</option>
<option>Spain</option>
</select>
I also have the same list of values in a div on my page e.g.
<div>
<span>Italy</span>
<span>France</span>
<span>Germany</span>
<span>Spain</span>
</div>
Using JQuery, I want to have it so - when a value in the dropdown is selected, the equivalent option in the div is briefly highlighted.
I've been struggling with the jQuery highlight plugin, but I believe the quicker way may be to use the highlight class of JjQuery UI. Apologies in advance for being a noob :)
Share Improve this question asked Nov 26, 2009 at 14:58 Ashley WardAshley Ward 11 silver badge2 bronze badges 1- "briefly highlighted" - .1 second, 1 minute, describe what this means. Please show what you have attempted (code wise) at this point. – Mark Schultheiss Commented Nov 26, 2009 at 15:08
2 Answers
Reset to default 6Using the highlight effect from jQuery UI:
$('#places').change(function() {
$('div span:contains(' + $(this).val() + ')').effect('highlight', {}, 1000)
})
When an item from the drop-down is selected, the span containing the respective text of the selected item is run through a animation of its background color ("highlight" effect) provided by the plugin.
Demo here.
Using JQuery UI plugin you can use the following
$('#places').change(function(){
$('span:contains('+ $(this).val() +')').effect('highlight', {color: 'red'}, 3000);
});
Change the color and 3000 as required.
本文标签: javascriptjQuery Highlight element on select optionStack Overflow
版权声明:本文标题:javascript - jQuery Highlight element on select option - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744754042a2623352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论