Skip to content
Advertisement

How can one get this value of a span with jQuery?

If we have this span, how can I get the value of sip, i.e. john.doe@xyz.de

<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
      <img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;                  
 </span>

Right now I use

var projectLeaderName = $('#projectLeader span').html();

to get the entire value of the span, but I don’t know how to get the value of sip with jQuery.

I don’t think this screenshot is necessary, but I’ll add it for completion:

enter image description here

Advertisement

Answer

Use jQuery.attr to get the value of an attribute:

var projectLeaderName = $('span img').attr('sip');
console.log(projectLeaderName);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span class="ms-spimn-presenceWrapper ms-imnImg ms-spimn-imgSize-10x10">
      <img name="imnmark" title="" showofflinepawn="1" class="ms-spimn-img ms-spimn-presence-disconnected-10x10x32" src="/_layouts/15/images/spimn.png?rev=23" alt="User Presence" sip="john.doe@xyz.de" id="imn_1,type=sip">;                  
 </span>
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement