How to get the value among the & if using data()?
example code:
<span data-name="username"> James</span>
i can get the value of data-name by using : $("span:visible").data("name"); // OUTPUT : username
but i want to get the value “James”, i tried add .text() & .val() at the end, but it is not working.
Thanks.
Jack
You can use an Attribute Equals selector to match the element, and the text() method to obtain its inner text content:
If the space character before
Jamesis significant, and you do not want it to be present in the value you fetch, you can apply $.trim():