- JQuery 특정 태그 선택 : find()

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <script src="http://code.jquery.com/jquery-1.7.min.js"></script>
    <script>
   
        //변수 선언
        var xml = "";
        xml += "<friends>";
        xml += "    <friend>";
        xml += "        <name>연하진</name>";
        xml += "        <language>Ruby</language>";
        xml += "    </friend>";
        xml += "    <friend>";
        xml += "        <name>윤명월</name>";
        xml += "        <language>Basic</language>";
        xml += "    </friend>";
        xml += "    <friend>";
        xml += "        <name>윤하린</name>";
        xml += "        <language>C#</language>";
        xml += "    </friend>";
        xml += "</friends>";

        $.noConflict();
        var J = jQuery;
        J(function () {
            var xmlDoc = J.parseXML(xml);
            J(xmlDoc).find("friend").each(function () {
                var outPut = "";
                outPut += "<div>";
                outPut += "     <h1>" + J(this).find("name").text() + "</h1>";
                outPut += "     <p>" + J(this).find("language").text() + "</p>";
                outPut += "</div>";

                document.body.innerHTML += outPut;
            });
        });
    </script>
    <title>Untitled Page</title>
</head>
<body>
</body>
</html>

 

+ Recent posts