cosi funziona ho cambiato l'attributo perché [p] non esiste con data-id e id al posto di this che ritengo si riferisca a window non all'oggetto vedi esempiocodice:<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="Generator" content="EditPlus®"> <meta name="Author" content=""> <meta name="Keywords" content=""> <meta name="Description" content=""> <title>Document</title> </head> <body> <a href="#" onclick="goal(document.getElementById('gl').getAttribute('data-id'));" id="gl" data-id="111"><h1>blablabla</a> <script> function goal(ar) { console.log(ar); if(ar==111) {var attr=91;}else{var attr=111;} document.getElementById("gl").setAttribute("data-id", attr); console.log(document.getElementById("gl").getAttribute("data-id")); } </script> </body> </html>![]()

Rispondi quotando