We have a requirement to get the attribute value and set it in the script file. So , How can we check the date-attribute-name(id,url,etc..) and set the value in the one trust script. Please verify and let me know your thoughts.
Thanks!
CodePudding user response:
you can use getAttribute & setAttribute methods
for example
document.getElementById('element').getAttribute('id')
document.getElementById('element').setAttribute('id', 'newId')
CodePudding user response:
You can use document.getElementById('element').getAttribute('id')
. When the attribute not exists you will get a null
.
So you can check later whether the attribute exists.
if (document.getElementById('element').getAttribute('id') !== null) {
// continue
}