Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-29-2008, 08:35 PM   PM User | #1
bilischan88
New Coder

 
Join Date: Nov 2007
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
bilischan88 is an unknown quantity at this point
Jquery problems using append

First off here's the code:

Code:
function getLastPost(id,reply){
   var isReply = (reply != undefined) ? "&reply="+reply:"&reply=0";
   $.ajax({
      type: "GET",
      url: "./ajaxphp/getPosts.php",
      data: "amount=1&ID="+id+isReply,
      dataType: "html",
      success: function(data){
         if(reply != undefined){
            if(!$("#post-"+id+" > ul").hasClass("postReply")){
               $("#post-"+id).append("<ul class=\"postReply\"></ul>");
            }
            
            $(data).hide().prependTo("#post-"+id+" > ul.postReply");
         }else{
            if(!$("#postMain").hasClass("postEntry")){
               $("#postMain").append("<ul class=\"postEntry\"></ul>");
            }
            
            $(data).hide().prependTo("ul.postEntry");
         }
         $("#post-"+id).fadeIn("slow");
         jsReply();
      }   
   });
}


So basically what this function is doing is getting an <li> of data and inserting it into a <ul>. However, if that ul isn't there it will append one. The "id" variable gets the id of the post and inserts it into ul.postEntry, however if the post is a reply to another it will create a ul.postReply within the parent post and put the <li> data into that. Everything in the "else" clause of the conditional works fine. It's just this line that will not work


Code:
if(!$("#post-"+id+" > ul").hasClass("postReply")){
               $("#post-"+id).append("<ul class=\"postReply\"></ul>");
            }
This conditional checks if there is a ul.postReply and if not make one. I checked it with an alert, and the conditional fires off properly however the append part never works which is weird because the other append works fine. What am I doing wrong?
bilischan88 is offline   Reply With Quote
Old 03-12-2010, 07:03 PM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
The only thing I can think is your element "#post-"+id doesn't exist..? Or is it appending the <ul> tag somewhere you're not expecting?
__________________
Fumigator is offline   Reply With Quote
Old 01-10-2011, 03:30 AM   PM User | #3
smith5
New to the CF scene

 
Join Date: Jan 2011
Location: USA
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
smith5 is an unknown quantity at this point
Hi ,...
The append method expects a string or DOM node as argument. You are calling it with an object (json). The contents of this object will depend on the data sent by the server. What does the alert print on your screen? Using FireBug you can inspect the properties available to your json object: console.log(json).
I hope this information will helps a lot,..

Regards
Smith

-----------------------
smith5 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:02 AM.


Advertisement
Log in to turn off these ads.