JQuery

 

 

<%@ 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>

 

 

about author

PHRASE

Level 60  라이트

Spare the rod, and spare the child. (매를 아끼면 아이들을 망친다)

댓글 ( 0)

댓글 남기기

작성

JQuery 목록    more