In my HTML code i want to check the following HTML code and automatically delete it on page load, how do i do it in JQuery ?
First Code that needs to be deleted
<table cellspacing="0" cellpadding="0" width="100%"><tbody><tr class="yellow"><td width="64%" valign="top">
Second Code that needs to be deleted
</td></tr></tbody></table>
You can’t remove ‘tags’ from a live HTML document. A document living in a web browser is a tree of DOM ‘nodes’. The nodes maintain the current state of the document, and were originally parsed from the tags in the HTML source. But that markup is now gone and cannot be recovered(*) or edited in the browser.
So you have a node representing the
tableelement, containing nodes for all the content between the<table>start-tag and the corresponding</table>end-tag. In this case that’s onetbodyelement node, which contains onetrelement node, which contains onetdelement node.To ‘unwrap’ the inner content you will need to take it out of the table and drop it in the place the table is. You can do this in jQuery using:
That is, replace the table with everything in its first cell.
(*: you can read
innerHTMLto get a string of markup from a DOM element node, but this serialisation is newly-generated markup and won’t typically be exactly the same as what you put in.)