$(this).val() not working to get text from span using jquery

后端 未结 7 1212
离开以前
离开以前 2020-12-01 00:23

Giving this html, i want to grab \"August\" from it when i click on it:

August

i tri

7条回答
  •  温柔的废话
    2020-12-01 01:10

    -None of the above consistently worked for me. So here is the solution i worked out that works consistently across all browsers as it uses basic functionality. Hope this may help others. Using jQuery 8.2

    1) Get the jquery object for "span". 2) Get the DOM object from above. Using jquery .get(0) 3) Using DOM's object's innerText get the text.

    Here is a simple example

    var curSpan = $(this).parent().children(' span').get(0);
    var spansText = curSpan.innerText;
    

    HTML

    testinput

提交回复
热议问题