I am trying to see the value with which the tag is displayed in the browser. For explanation purposes I will mention "text" instead of "value". initially it has the text "test" then through a function I change the text to "auxiliary" (string that is in an object of a .json file), later in the function I add an event
document.getElementById('ttlSECT1_1').addEventListener("click",ver);
and in a different function I create the following function:
function ver(e) {
if(!e) e = window.event;
var a = e.target.id;
var b = a.textContent;
console.log(a);
}
and this is the tag in the html:
<p id="ttlSECT1_1">título</p>
The part of the variable b in the view function does not work for me, specifically .textContent
I have also tried with .innerText
, .innerHTML
and .value
but I only see the undefined in the console.
How can I see the text in the console? I do this because in that function I want to save that data in thesessionStorage
You can achieve it using
.textContent
but ine.target
like this: