If you want to replace only <a> element and leave everything else in <div>
as is, you need to find that <a> element first:
var aOld = document.querySelector("div.foobar a.aaa"); // returns first
match
Then you need to create new <a> element:
var aNew = document.createElement("a");
aNew.href = address;
aNew.innerHTML = address; // content of <a> element
And last thing to do is to replace this element with the old one:
aOld.parentNode.replaceChild(aNew, aOld);
W dniu poniedziałek, 28 marca 2016 10:52:51 UTC+2 użytkownik Ben napisał:
>
> Assume I have the following code:
>
> <div class"foobar">
> ....
> <a class="aaa" .....> .... </a>
> ....
> </div>
>
> Now I want to completely replace the <a> element (including child stuff)
> by another.
> Then the follawing does not work:
>
> var address = document.URL;
> var div = document.getElementsByClassName("foobar.aaa")[0];
> div = "<a href=\"" + address + "\">" + address + "</a>";
>
> How else does that work?
>
> Ben
>
>
>
>
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.