jQuery get DOM element as string

前端 未结 5 2079
走了就别回头了
走了就别回头了 2020-12-30 03:16

Say I have

$(\":input[type=text]:first\")

How do I get



        
5条回答
  •  自闭症患者
    2020-12-30 03:37

    Following on what @Blazemonger have answered, if you are going to send this html content to the server, it's worth to get rid of all unnecessary tags, white-spaces and line-breaks that don't add any value.

    var quote = $(".invoice") //get hidden print-version DOM element
        .clone()
        .wrap('
    ') .parent() .html() .replace(/ /g, '') //get rid of indentation spaces .replace(/(\r\n|\n|\r)/gm, "") //get rid of line breaks .replace(//g, ""); //get rid of comment tags

    My html had 50kb, after getting rid of this stuff, it got reduced to 4kb!

提交回复
热议问题