table
How to expand a table from
...">

How to "expand" tags?

I have this HTML code:

<center><table><tr><td>table</td></tr></table></center>

How to expand a table from <center>

Sorry, I'm not even sure how to get started.

Many thanks

+3
source share
4 answers

This function works fine,

jQuery.fn.unwrap = function (el) {
    return this.each( function(){
      $(this.childNodes).appendTo(this.parentNode );
    });
};
+3
source

I rather want to completely get rid of the central tag or replace it with some div. The center icon is not wrapped in anything. Any ideas?

Is it nothing wrapped? then, of course, wrap it with something!

var $center = $('center');
var $newReplacement = $("<div></div>");

$center.wrap($newReplacement);
$newReplacement.html($center.html());

As an alternative:

var $center = $("center");
$("<div></div>")
    .insertBefore($center)
    .html($center.html())
;
$center.remove();

And again, but this time without losing events:

var $contents = $("center > *")
    .clone(true)   // not sure if this is needed
    .appendTo(
         $("<div></div>").insertBefore("center")
    )
;
$("center").remove();
+5
source
var $table = $("center table");
var $center = $table.parent();
$table.insertBefore($center);
$center.remove();
+3

, "" :

    $("center").each(function(){
       $(this).replaceWith($(this).html());
    });

.each , $(this)

In your case, if your page has more than one central tag, you also want to mark the one you want to remove using the id attribute, and select it something like this:

$("#zapthis").each(...
+1
source

Source: https://habr.com/ru/post/1718796/


All Articles