1

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!

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
Sriga Devi
  • 11
  • 1

2 Answers2

0

you can use getAttribute & setAttribute methods

for example

document.getElementById('element').getAttribute('id')
document.getElementById('element').setAttribute('id', 'newId')
Gurkan Atik
  • 468
  • 4
  • 10
0

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
}
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79