Ayodhyankit Paul Ayodhyankit Paul - 3 years ago 154
jQuery Question

How replace <a> tag with different value in browser console via javascript?

I want to replace something with javascript with different value :

so i selected that tag path and getting it by :

document.querySelector('#2311 > div._20bp > div._4_j4 > div:nth-child(2) > div._4rv3 > div > div._4rv4 > a');


the tag looks like this :

<a aria-label="wow" class="_5j_u _4rv9 _30yy _39bl" role="button" title="wow" href="#"><svg aria-labelledby="js_ib" version="1.1" viewBox="-1 -1 40.16 42.24" preserveAspectRatio="xMinYMax meet" style="height: 85%; width: 66%;"><title id="js_ib">Thumbs-up sign</title><path d="M935.36,1582.44a0,0,0,0,0,0,.06,3.59,3.59,0,0,1-.72,6.53,0,0,0,0,0,0,0,3.56,3.56,0,0,1,.71,2.13,3.6,3.6,0,0,1-3,3.54, 0,0,0,0,0,0,.05,3.56,3.56,0,0,1,.38,1.61,3.61,3.61,0,0,1-3.42,3.6H910v-19.6l5.27-7.9a4,4,0,0,0,.66-2.31l-0.1-4c-0.22-2.4-.09-2.06, 1.13-2.37,2-.51,7.16,1.59,5.13,12.17h11.06A3.59,3.59,0,0,1,935.36,1582.44ZM899,1581h7v22h-7v-22Z" transform="translate(-898.5 -1563.26)" fill="transparent" fill-rule="evenodd" stroke="#13CF13" stroke-linecap="round" stroke-width="5%"></path></svg></a>


I want to replace this tag with :

<a data-hover="tooltip" data-tooltip-content="Press" class="_30yy _38lh _39bl" href="#" style="color: rgb(19, 207, 19);">Send</a>


i want to do this in javascript browser console

how to do this ?

I tried :

document.querySelector('#2311 > div._20bp > div._4_j4 > div:nth-child(2) > div._4rv3 > div > div._4rv4 > a').style="<a data-hover="tooltip" data-tooltip-content="Press" class="_30yy _38lh _39bl" href="#" style="color: rgb(19, 207, 19);">Send</a>"


But didn't work.

Answer Source

Try using .outerHTML like so:

document.querySelector('#2311 > div._20bp > div._4_j4 > div:nth-child(2) > div._4rv3 > div > div._4rv4 > a').outerHTML = '<a data-hover="tooltip" data-tooltip-content="Press" class="_30yy _38lh _39bl" href="#" style="color: rgb(19, 207, 19);">Send</a>';

You can read more about it on MDN.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download