Assistance with HTML structure building with JQ
Hey all.
I have been finding tutorials all over the place and have managed to get this far without needing very specific help. So, I feel rather proud :)
Anyways, here is my code base thus far:
- $.getJSON("search.php?jsoncallback=?", function(data) {
-
- //loop through all items in the JSON array
- for (var x = 0; x < data.length; x++) {
-
- //create a container for each comment
- var div = $("<div>").addClass("entry round").appendTo("#characters");
-
- //add author name and comment to container
- $("<img>").addClass("char-img").attr("src", data[x].charimg).appendTo(div);
- $("<h2>").text(data[x].posting_title).appendTo(div);
- $("<p>").text(data[x].description).appendTo(div);
- $("<p>").addClass("tags").wrapInner("<span>Tags:</span>").appendTo(div);
-
- }
- });
So, all of that code works perfectly.
My problem area happens on line 13. I am trying to make the HTML come out like this:
- <p class="tags">
- <span>Tags:</span>
- <a href="#">1</a>,
- <a href="#">2</a>,
- <a href="#">3</a>
- </p>
This structure is consistent and the 1/2/3 are replaced with my variable names and the # will be replaced with variable links as well. So, my question is how do I get the "<a></a>" (there will always be 3 links) to come in after the "wrapInner span" that I have on line 16 of my JS code.
Thanks!