首页 > 解决方案 > Change value of label element inserting href inside

问题描述

I have this element:

<li class="choice-1 depth-1"><input type="checkbox" id="wpforms-1028-field_3_1" name="wpforms[fields][3][]" value="Acepto la política de privacidad" required ><label class="wpforms-field-label-inline" for="wpforms-1028-field_3_1">Acepto la política de privacidad</label></li>

I want to change this text: Acepto la política de privacidad

to this: Acepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>

I have tried this code:

document.getElementById("wpforms-1028-field_3_1").value="Acepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>"

But it doesn't work because it seem I am not inside the "label" element.

标签: javascripthtml

解决方案


您可以使用文档查询选择器

document.querySelector(".wpforms-field-label-inline").innerHTML = "cepto la <a href='https://XXXX/gdpr/'>política de privacidad TEST</a>";

推荐阅读