4

I want to fetch Span value from below code sample.

<ul style="list-style:none;padding:0px;margin:0px;">
  <li scriptclass="SharePointFileAttachmentContainer" class="a3_KcMvdcLcp51gEaVY_0" id="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0_V1_I1_SPFAC26_SPI124" formid="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0" originalid="V1_I1_SPFAC26_SPI124" viewdatanode="38">
    <span style="" onmouseover="return LeafControl.OnWrappingSpanMouseOver(this, event);" onmouseout="return LeafControl.OnWrappingSpanMouseOut(this, event);">
      <span id="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0_V1_I1_SPFAC26_SPI124_SPFA1" scriptclass="SharePointFileAttachmentItem" class="b_KcMvdcLcp51gEaVY_0 a2_KcMvdcLcp51gEaVY_0 bh_KcMvdcLcp51gEaVY_0" direction="ltr" viewdatanode="39" formid="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0" originalid="V1_I1_SPFAC26_SPI124_SPFA1" style="margin:0px; width: 100%; display:inline-block;">
        <a href="#" style="text-decoration:none; border:none;" onclick="return (SharePointFileAttachmentItem.OnClick(this, event));" onfocus="return (SharePointFileAttachmentItem.OnFocus(this, event));" onkeypress="return (SharePointFileAttachmentItem.OnKeyPress(this, event));">
          <img title="Click here to delete the file. EAMS Masters.docx" alt="Click here to delete the file. EAMS Masters.docx" style="cursor: hand;border:none;vertical-align:middle;margin-right:1px;" src="/_layouts/inc/ipfsfileattachmentdelete.png?rev=yS8PMFXDZDJFrumpJ9CThg%3D%3D">
        </a>
        <span>EAMS Masters.docx</span>
      </span>
    </span>
  </li>
  <li scriptclass="SharePointFileAttachmentContainer" class="a3_KcMvdcLcp51gEaVY_0" id="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0_V1_I1_SPFAC26_SPI125" formid="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0" originalid="V1_I1_SPFAC26_SPI125" viewdatanode="40">
    <span style="" onmouseover="return LeafControl.OnWrappingSpanMouseOver(this, event);" onmouseout="return LeafControl.OnWrappingSpanMouseOut(this, event);">
      <span id="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0_V1_I1_SPFAC26_SPI125_SPFA1" scriptclass="SharePointFileAttachmentItem" class="b_KcMvdcLcp51gEaVY_0 a2_KcMvdcLcp51gEaVY_0 bh_KcMvdcLcp51gEaVY_0" direction="ltr" viewdatanode="41" formid="ctl00_m_g_92fd70a8_aeaf_433d_8f82_e1ead1630fec_FormControl0" originalid="V1_I1_SPFAC26_SPI125_SPFA1" style="margin:0px; width: 100%; display:inline-block;">
        <a href="#" style="text-decoration:none; border:none;" onclick="return (SharePointFileAttachmentItem.OnClick(this, event));" onfocus="return (SharePointFileAttachmentItem.OnFocus(this, event));" onkeypress="return (SharePointFileAttachmentItem.OnKeyPress(this, event));">
          <img title="Click here to delete the file. 123.docx" alt="Click here to delete the file. 123.docx" style="cursor: hand;border:none;vertical-align:middle;margin-right:1px;" src="/_layouts/inc/ipfsfileattachmentdelete.png?rev=yS8PMFXDZDJFrumpJ9CThg%3D%3D">
        </a>
        <span>123.docx</span>
      </span>
    </span>
  </li>
</ul>

From Above code sample I want <span>EAMS Masters.docx</span> and <span>123.docx</span> this span values. I have multiple <li> like this.

So please suggest me solution in Jquery or Javascript.

Thanks, Digambart

2
  • what is the pattern? to have .docx inside? or all span? Commented Jul 29, 2013 at 12:26
  • First and foremost, move your inline styles into classes. Then we can start helping you Commented Jul 29, 2013 at 12:27

8 Answers 8

2

If you want each li's 3rd span's content:

var i=1;
$('ul li').each(function(){
    var span_val=$(this).find('span span span').text();
    //code for doing something with span_val
});

working example here : http://jsfiddle.net/s3C2X/1/

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

Comments

1

How about doing it like this

spans = $('li[scriptclass="SharePointFileAttachmentContainer"]').find('span[id^="ctl00_m"]').find('span');
console.log( spans );

the breakdown (good for studying)

  1. li tags with attribute of scriptclass
  2. span with ids that begins with ctl00_m
  3. finally find the span inside it.

if you want to loop through each spans found:

spans.each(function(){
    console.log( $(this).text() );
});

Working sample http://jsfiddle.net/fedmich/HdMTH/

Comments

1
var mySpans = $("li span span span");

Comments

0

You can do this -

var spans = $('li').map(function(){
       return $(this).find('a').next('span');
});

Comments

0

You can do this using below code.

$('li').each(function(){
   $(this).find('span span:last').css('border','1px solid red'); 
});

in above code it will get the first span inside li and inside that span it will get last span so you will have your span as result.

SEE DEMO

Comments

0

Try

$('li.a3_KcMvdcLcp51gEaVY_0').find('span span span').each(function(){
    console.log($(this).text())
})

Demo: Fiddle

Comments

0

Far more elegant solution:

$('li span:nth-child(3)')

Check out the docs

Comments

0

Since you've class a3_KcMvdcLcp51gEaVY_0 for liand a single a anchor tag. You can simple have

   $('.a3_KcMvdcLcp51gEaVY_0 a').next('span').text();

check this JSFiddle

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.