Home > Net >  How can i get the text of a span element using javascript?
How can i get the text of a span element using javascript?

Time:01-25

Edited for tags and further explanation of the question

Hello ,i am fairly new to the web programming, sorry in advance if this sounds out of place. My question is, i need to get customer's name and number from this <span title="${Customer No}">${Customer Name}-${Customer No}</span> area, which is inside the code below, any help would be very appreciated.

<div  id="ChoosenCustomer">
                                        <div  id="branches">
                                            <div  dojoattachpoint="_tagsContainer">
                                                <div  name="ChoosenTags" id="" is-clicked="true">
                                                    <span  title="${Customer No}">${Customer Name}-${Customer No}</span>
                                                    <span id="RemoveCustomer"  search-id="" click=DeleteCustomer()></span>
                                                    <input type="hidden" id="" value="${Customer No}" is-clicked="true">
                                                </div>
                                            </div>
                                        </div>
                                    </div>

CodePudding user response:

try this:

let span_text = document.querySelector('.your-element-class').textContent;

with jQuery:

let span_text = $('.your-element-class').text();

CodePudding user response:

in your case:

document.getElementById("anid").innerText;

and add the id to your element

CodePudding user response:

Simply you can use jquery on your project and :

var SpanText = $('.tag-element-content').text();
  •  Tags:  
  • Related