0
How to find the span text Achievements, QA , Dept having parent span Talk using Jquery.

im supposed to generate dynamic html like below with different parent span text and save the li>span values in database

<span class="chntxt">Talk(parent)</span>

<div title="" class="elemenaryschool_chn chzn-container chzn-container-multi">

<ul class="chzn-choices">

<li seq="1" subseq="1" id="58" class="search-choice">
<span>Achievements</span>
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li>

<li seq="1" subseq="2" id="59" class="search-choice">
<span>QA</span> 
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li>

<li seq="1" subseq="3" id="60" class="search-choice">
<span>Dept</span> 
<a rel="3" class="search-choice-close" href="javascript:void(0)"></a></li>

<li class="search-field"><span contenteditable="true" style="width: 25px;"></span></li>

</ul></div>
2
  • 1
    question not clear.. rephrasing needed. Commented Mar 29, 2014 at 5:08
  • try to make a answer from your last question : jQuery find element in ul li span Commented Mar 29, 2014 at 5:15

2 Answers 2

1

Here is how you can select the spans themselves. I'm assuming by saying you "have parent span Talk" that you want to traverse the tree from that start point. Here's what I came up with:

jQuery('.chntxt').on('click', function(){
    jQuery(this).nextAll().find('span').css('border', '1px solid red');
});

The .css() is just to show what is being selected. You could change that to .text() and use .each() to store them all as variables or in an array or something.

Sign up to request clarification or add additional context in comments.

Comments

0

In order to use jQuery to find objects, you can use jQuery.find()

http://api.jquery.com/find/

$( "span" ).parent().find( "li" ).css( "background-color", "red" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.