且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

客户端 HTML 缩小

更新时间:2022-10-15 14:22:50

我设法实现了我想要的,甚至为它创建了一个 jQuery 插件.

jQuery.fn.clearWhiteSpace = function () {var htmlClone = this.html().replace(/\n[ ]*/g,"");this.html(htmlClone);返回这个;}$(".parentDiv").clearWhiteSpace();

我在 jsfiddle

中写了一个例子

但是感谢您的所有努力.:)

Is there a way to this kind of minification with javascript and update the DOM (clientSide)

Input:

<div class="parentDiv">
    <div class="childDiv">Some text</div>
    <div class="childDiv">Some text</div>
</div>

Output:

<div class="parentDiv"><div class="childDiv">Some text</div><div class="childDiv">Some text</div></div>

I know its useless doing the minification after downloading all the content. The point here is to stop the identation to create gaps between my divs. I know that if I put a comment between the tags the gap won't appear but it gets difficult to understand the code with so many comments between my div tags.

See this [post] and you'll understand what I mean.

I managed to achieve what I wanted and even created a jQuery plugin to it.

jQuery.fn.clearWhiteSpace = function () {
    var htmlClone = this.html().replace(/\n[ ]*/g,"");
  this.html(htmlClone);

  return this;
}

$(".parentDiv").clearWhiteSpace();

there is an example I wrote in jsfiddle

But thanks for all your effort. :)