Eyal Eyal - 1 year ago 114
jQuery Question

Get the next span with class

I have the following Html structure for every

object in my page:

<div class="clsPropertyDiv clsPropertyId_16 ">
<span class="inputTitle">You can select multiple items</span><br>
<select id="select_16" multiple="multiple" style="display: none;">
<option class="" value="2699" id="opt_2699">Rusian </option>
<option class="clsOptionSelected" value="2700" id="opt_2700">English </option> // take this text
<option class="" value="2702" id="opt_2702">Hebrew</option>

<div class="ms-parent multipleSelection" multiple="multiple">
<button type="button" class="ms-choice">
<span class="spnMulti"></span> // insert here.
<div class=""></div>

I need to get the selected text and insert it to:
<span class="spnMulti"></span>

This is what I was trying to do:

$('.selectOptions option').each(function() {
if ($(this).hasClass('clsOptionSelected') {
var selectedText = $(this).text();
$(this).next('.spnMulti').text("selectedText ");


Answer Source

The .spnMulti don't are childen of selectOptions. You need call the parent div and after find by spnMulti.



and add class to select "selectOptions", in selector, you use: "$('.selectOptions option')" and not have a .selectOptions class in select.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download