Reputation: 604
i have this type of code all over my code
<td><font color="#3586DF"><b><span>1</span></b></font></td>
<td><font color="#3586DF"><b><a href="#"><font color="#3586DF">2</font></a></b></font></td>
i want to replace b with strong and remove font tag
Result should be
<td><strong><span>1</span></strong></td>
<td><strong><a href="#">2</a></strong></td>
how i do this with jquery , javascript or Css
Upvotes: 0
Views: 1542
Reputation: 22323
You can find b tag inside table using loop and replace it like this.
$('#testtable').find('tr > td > font > b').each(function() {
$(this).replaceWith($('<strong>' + $(this).html() + '</strong>'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id='testtable'><tr>
<td><font color="#3586DF"><b><span>1</span></b></font></td>
<td><font color="#3586DF"><b><a href="#"><font color="#3586DF">2</font></a></b></font></td>
</tr></table>
Upvotes: 0
Reputation: 171690
Can use jQuery replaceWith()
$('font').replaceWith(function() {
return $(this).contents()
})
$('b').replaceWith(function() {
return $('<strong>').append($(this).html())
})
console.log($('table').html())
strong,
strong a {
color: red
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<font color="#3586DF"><b><span>1</span></b></font>
</td>
<td>
<font color="#3586DF"><b><a href="#"><font color="#3586DF">2</font></a></b></font>
</td>
</tr>
</table>
Upvotes: 1