I have text in a tag <span>
. I want to wrap part of this text in another element tag with an identifier that is not in the underlying HTML. Since I cannot change the basic HTML, I am forced to use JavaScript/JQuery
for this.
I have this HTML code:
<span id="my_span">John<input type="hidden" name="firstname" value="John" id="my_input1">
<br>Smith<input type="hidden" name="lastname" value="Smith" id="my_input2">
</span>
I want to add a tag <a>
with an identifier to texts within this range. The text I want to wrap is dynamic, so I cannot use the value inside as such to search for and target it. The HMTL code should look like the following after applying the code JavaScript/JQuery
:
<span id="my_span"><a id="added_a_tag1">John</a><input type="hidden" name="firstname" value="John" id="my_input1">
<br>
<a id="added_a_tag2">Smith</a><input type="hidden" name="lastname" value="Smith" id="my_input2">
</span>
It sounds simple, but I could not reach it.
I will need to target those newly added identifiers for something even later.
I appreciate your answers.