<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!doctype html> <html lang="en"> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> </head> <body> <div class="test"> <ul> <li>test</li> </ul> </div> <button onclick="outHTML('.test')">버튼</button> <script> $.fn.outerHTML = function() { var el = $(this); if( !el[0] ) return ""; if (el[0].outerHTML) { return el[0].outerHTML; } else { var content = el.wrap('<p/>').parent().html(); el.unwrap(); return content; } }; function outHTML(id){ console.log($(id).outerHTML()); alert($(id).outerHTML()); } </script> </body> </html>
댓글 ( 4)
댓글 남기기