Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i get the content of a specific div sharing the same class with other div ? i get an empty string with 'this'

What i tried :

const adressLine = $('.adressLine');
    adressLine.on('click',()=>{
        console.log('button cliked');
        var text = adressLine.text();
        console.log(text);
    });

console result, i get all of the strings, not what i want :

Result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

so i find a solution in other discussions:

const adressLine = $('.adressLine');
    adressLine.on('click',()=>{
        console.log('button cliked');
        var text = $(this).text();
        console.log(text);
    });

it returned me an empty string , why ?

Second result

>Solution :

This happens because you are using an arrow function.

Try with

const adressLine = $('.adressLine');
adressLine.on('click',function(){
    console.log('button cliked');
    var text = $(this).text();
    console.log(text);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading