In my php file I have a span under a button which in turn is inside a td
<td class="floating-td"><button class="count"><span id="compareCounts"><?php echo $listInfo; ?></span> </button></td>
At the end of the file while trying to fetch the value of span through ID I’m not getting anything. But when I check in the Chrome console, I do get the values there.
jQuery(document).ready(($) => {
var countVal = $('#compareCounts').text();
// var countVal = document.getElementById("compareCounts").value;
console.log("qwerty countVal bc-html: ", countVal);
}
As shown above, I tried using JS and jquery, in both the cases I’m not getting the value while running the code. Though trying $('#compareCounts').text();
and document.getElementById("compareCounts").value
in the console tab in Chrome does give the value.
What could be wrong here ?
2
Answers
I think this will help you. I will try using jquery with on load and on button click how to get the value and console it.
If you have multiple dynamic values at that time on btn click you can get the span value