Why is the console undefined when I store a simple jquery selector in a variable? -
i want add xml html using ajax can't seem use jquery store div in variable need. when call variable on console returns undefined. @ moment have:
var target = $(this).parent().find(".thread")[0]; console.log(target); the html want insert xml in looks this:
<div class="thread"></div> here javascript file:
var threads = (function() { var pub = {}; function producethreads(data, target) { $(target).append("<ul>"); $(data).find("thread").each(function() { var title = $(this).find("title")[0].textcontent; var posts = $(this).find("posts")[0].textcontent; $(target).append("<li>" + title + "</li>"); $(target).append("<li>" + posts + "</li>"); }); $(target).append("</ul>"); } function showthreads() { var target = $(this).parent().find(".review")[0]; console.log(target); var data = "forum.xml"; $.ajax({ type: "get", url: data, cache: false, success: function(data) { producethreads(data, target); } }); } pub.setup = function() { showthreads(); }; return pub; }()); $(document).ready(threads.setup); and html:
<!doctype html> <html> <head> <title>forum</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <link rel="stylesheet" type="text/css" href="forum.css"> <script src="jquery-1.10.2.min.js"></script> <script src="forum.js"></script> </head> <body> <header> <h1>forum</h1> </header> <p> <a href="users.html">users</a> </p> <div class="thread"></div> </body> </html> the idea have xml list producethreads function visible html loads, can hardly have when can't store target variable. jquery version using 1.10.2.min.
Comments
Post a Comment