Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

JQUERY UI Accordion issue

Posted on 2013-06-25
10
Medium Priority
?
401 Views
Last Modified: 2013-06-30
Hello,

I am trying to use the JQuery Accordion and I can't seem to get it to work properly with the HTML which I *think* is correct.  HTML is here.  Instead of two accordion panels "Section 1" and "Section 2", I get 3 panels.  I think all the "divs" are closed so I can't figure out why this isn't displaying properly.

Thanks for any help!

Cheers,

<h3> Section1</h3>
<div>
  <div>
    <div style='width:100%; overflow:hidden;'>
      <div id='myPic-0-0' style='width:50px; height:50px;  float:left; '></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>This is a test message</div>
    </div>
    <div style='width:100%; overflow:hidden;'></div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;'>23/04/2013</div>
    </div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='height:30px;'></div>
    </div>
  </div>
  <div>
    <div style='width:100%; overflow:hidden; margin-left:40px;'>
      <div id='myPic-0-1' style='width:50px; height:50px;  float:left; '></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>OK, we got it</div>
    </div>
    <div style='width:100%; overflow:hidden;'></div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px; padding-left:45px;'>24/04/2013</div>
    </div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='height:30px;'></div>
    </div>
  </div>
</div>
<h3> Section 2</h3>
<div>
  <div>
    <div style='border-top:2px solid gray; width:100%; overflow:hidden; padding-top: 10px; margin: 2px 0px 0px 0px;'>
      <div id='myPic-1-0' style='width:50px; height:50px;  float:left; '></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>This is test 2</div>
    </div>
    <div style='width:100%; overflow:hidden;'></div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;'>24/04/2013</div>
    </div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='height:30px;'></div>
    </div>
  </div>
  <div>
    <div style='width:100%; overflow:hidden; margin-left:40px;'>
      <div id='myPic-1-1' style='width:50px; height:50px;  float:left; '></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>My next reply</div>
    </div>
    <div style='width:100%; overflow:hidden;'></div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px; padding-left:45px;'>25/04/2013</div>
    </div>
    <div style='width:100%; overflow:hidden;'>
      <div style='width:60px; height:10px;  float:left;'></div>
      <div style='height:30px;'></div>
    </div>
  </div>
</div>

Open in new window

0
Comment
Question by:1Cougar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39274344
It's seem ok, again What's about using double quotes like:
<h3> Section1</h3>
<div>
  <div>
    <div style="width:100%; overflow:hidden;">
      <div id="myPic-0-0" style="width:50px; height:50px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;">This is a test message</div>
    </div>
    <div style="width:100%; overflow:hidden;"></div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;">23/04/2013</div>
    </div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="height:30px;"></div>
    </div>
  </div>
  <div>
    <div style="width:100%; overflow:hidden; margin-left:40px;">
      <div id="myPic-0-1" style="width:50px; height:50px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;">OK, we got it</div>
    </div>
    <div style="width:100%; overflow:hidden;"></div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px; padding-left:45px;">24/04/2013</div>
    </div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="height:30px;"></div>
    </div>
  </div>
</div>
<h3> Section 2</h3>
<div>
  <div>
    <div style="border-top:2px solid gray; width:100%; overflow:hidden; padding-top: 10px; margin: 2px 0px 0px 0px;">
      <div id="myPic-1-0" style="width:50px; height:50px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;">This is test 2</div>
    </div>
    <div style="width:100%; overflow:hidden;"></div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;">24/04/2013</div>
    </div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="height:30px;"></div>
    </div>
  </div>
  <div>
    <div style="width:100%; overflow:hidden; margin-left:40px;">
      <div id="myPic-1-1" style="width:50px; height:50px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;">My next reply</div>
    </div>
    <div style="width:100%; overflow:hidden;"></div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px; padding-left:45px;">25/04/2013</div>
    </div>
    <div style="width:100%; overflow:hidden;">
      <div style="width:60px; height:10px;  float:left;"></div>
      <div style="height:30px;"></div>
    </div>
  </div>
</div>

Open in new window


Where is the exact problem it may be in your script?? You have separate sections in div only.
0
 

Author Comment

by:1Cougar
ID: 39274358
I can't use double quotes because it is built and inserted appended to the "accordion" div via jquery append.

The HTML shows up as it should but instead of just 2 panels, there are 3.  One panel stops after the date and before the div with "OK, we got it." and then the next panel stops AFTER the h3 "Section 2".  The 3rd panel starts with the divider line and includes the two comments.

??
0
 
LVL 15

Expert Comment

by:Jagadishwor Dulal
ID: 39274368
But how can we explain what is your script??
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:1Cougar
ID: 39274410
The HTML I pasted is an echo of the HTML just before it is appended to the div with Jquery append and before the accordion is initialized with $("#accordion").accordion();
0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 39274438
You have

$("#accordion").accordion();

But in your code you don't show the id="accordion" element.

Also can you show the JQuery that you are using to initialise.

Or a link to the problem.

Posting some of the code does not help us if that is not where the problem is.
0
 

Author Comment

by:1Cougar
ID: 39274446
Here is a snippet of the code--would this be enough?

if(what==1){
	
	myHTML = "<div id='accordion'></div>";
	$("#fifth").append (myHTML);
	myHTML = "";
	myHTML1 = "";
	
	
	$.getJSON(url, function(result){
		
		
		for (var i = 0; i < result.data.length; i++) { 
		
			for (var j = 0; j < result.data[i].Messages.length; j++) { 
					var myAvatarLink = "http://www.mywebsite.com/UserAvatars/"+result.data[i].Messages[j].avatar;
					
					var myComment = result.data[i].Messages[j].message;
					var myDate = result.data[i].Messages[j].msgDate;
					if (j==0) {
						//myHTML="<h3> Section1</h3><div>";
						if(i==0){
							
							myHTML = "<h3> Section1</h3><div><div><div style='width:100%; overflow:hidden;'><div id='myPic-"+ i + '-'  +j+"' style='width:50px; height:50px;  float:left; '></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>"+myComment+"</div></div><div style='width:100%; overflow:hidden;'></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;'>"+myDate+"</div></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='height:30px;'></div>";
						} else {
							myHTML = "</div></div><h3> Section 2</h3><div><div><div style='border-top:2px solid gray; width:100%; overflow:hidden; padding-top: 10px; margin: 2px 0px 0px 0px;'><div id='myPic-"+ i + '-'  +j+"' style='width:50px; height:50px;  float:left; '></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>"+myComment+"</div></div><div style='width:100%; overflow:hidden;'></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px;padding-left:5px;'>"+myDate+"</div></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='height:30px;'></div>";
							
						}
					} else {
						
						myHTML = "</div></div><div><div style='width:100%; overflow:hidden; margin-left:40px;'><div id='myPic-"+ i + '-'  +j+"' style='width:50px; height:50px;  float:left; '></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; font-size:12px;'>"+myComment+"</div></div><div style='width:100%; overflow:hidden;'></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='margin-left:65px; margin-top:0px;width:500px; text-align:left; font-family:Verdana, Geneva, sans-serif; padding-left:5px; color:#666; font-style:italic; font-size:10px; padding-left:45px;'>"+myDate+"</div></div><div style='width:100%; overflow:hidden;'><div style='width:60px; height:10px;  float:left;'></div><div style='height:30px;'></div></div>";
						
					}
					
					myHTML = myHTML+"</div>";
					myHTML1 = myHTML1+myHTML;
					$("#accordion").append (myHTML);
					$("#myPic-" + i + '-'  +j).append("<img src='"+myAvatarLink+"' height='50' width='50'/>");
					myHTML="";
					
					
			}
		
		}
		myHTML="</div></div>";
		myHTML1=myHTML1 + myHTML;
		alert(myHTML1);
		$("#accordion").append (myHTML);
		$("#accordion").accordion();
		return false;});
}

$("#fifth").show();
	
}

Open in new window

0
 
LVL 59

Expert Comment

by:Julian Hansen
ID: 39274522
Wrapping your original post in <div id="accordian"> and binding JQueryUI accordian to this seems to work - only shows two items

Do you have a link we can look at - a link?
0
 

Author Comment

by:1Cougar
ID: 39274541
can I send you a private link?
0
 

Accepted Solution

by:
1Cougar earned 0 total points
ID: 39274679
Hello,

I solved the issue.  It had to do with appending the images in the HTML.  I don't know exactly why this caused problems but once I changed the way this was done, it works.

Thanks so much!

Cheers!
0
 

Author Closing Comment

by:1Cougar
ID: 39287890
The solution was to modify the existing code
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question