I need to replace value in noscript.
I tried the following code but it doesn't replaces the value.
Would you please let me know how to fix the code?
I tried:
jQuery("ls-slot-shortcode_actions a noscript").replaceWith("width=42");
Existing Code:
<li class="ls-slot-shortcode_actions">
<a href="https://www.myhome.com">
<img scr="https://www.myhome.com/img/cco.png">
<noscript>
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
</noscript>
</a>
</li>
Thank you.
this code does the job:
let selector = $(".ls-slot-shortcode_actions a noscript");
let txt = selector.text();
console.log("before modification:" + txt)
let newtxt = txt.replace(/width=".*?"/, 'width="42"');
selector.text(newtxt);
console.log("after modification:" + selector.text())
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li class="ls-slot-shortcode_actions">
<a href="https://www.myhome.com">
<img scr="https://www.myhome.com/img/cco.png">
<noscript>
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
</noscript>
</a>
</li>
I you have more lines, and you want to keep just one, you could do that:
let selector = $(".ls-slot-shortcode_actions a noscript");
let txt = selector.text();
console.log("before modification:" + txt)
let newtxt = txt.replace(/width=".*?"/g, 'width="xx"');
newtxt = newtxt.replace(/width="xx"/, 'width="42"');
newtxt = newtxt.replace(/"<img width=.xx. .+>"/g, "");
selector.text(newtxt);
console.log("after modification:" + selector.text())
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<li class="ls-slot-shortcode_actions">
<a href="https://www.myhome.com">
<img scr="https://www.myhome.com/img/cco.png">
<noscript>
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
"<img width="18" height="12" class="ls-flag" src="https://www.myhome.com/img/cco.png" >"
</noscript>
</a>
</li>