Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
replace elements using jQuery

I have the following HTML rendered out in powerapps portal and I would like to replace all the occurrence of

    <font size = 3>..... </font>

with

    <div class="legend">... </div> 

I have tried the snippet below, but it didn't replace it:

    var $descBox = $("<font size = 3>"); $descBox.replaceAll("<div class='legend well'>");
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  • To search for existing elements, use CSS expressions in jQuery's $().
  • To create new elements, use HTML code in jQuery's 's $().
  • .replaceAll() is a string function. You meant .replaceWith().

i.e.

$("font[size=3]").replaceWith( $("<div class='legend well'>") );

or, shorter

$("font[size=3]").replaceWith("<div class='legend well'>");

Exchanging only the <font> elements without also replacing their contents requires a couple more steps.

$("font[size=3]").each(function () {
  // insert new container div after each `<font>`
  var $div = $("<div class='legend well'>").insertAfter(this);

  // remove the `<font>` and append its children to the new container
  $(this).remove().children().appendTo($div);
});
div.legend {
   color: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<font size="3">
  <p>elements to keep</p>
</font>
<font size="3">
  <p>more elements to keep</p>
</font>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!