Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JSON: Using append to create inline menu from JSON

Posted on 2014-01-10
4
Medium Priority
?
306 Views
Last Modified: 2014-01-10
Hello,

I am reading in JSON and appending to a "menu" div on my page.  I cannot figure out how to get each nested div within the menu div to add "inline" as I want to use it as a menu.  They all show up on top of eachother.  Code is below.  

Many thanks!

$.each(result.rows, function(i,val){
mymenu = '<div id="'+result.rows[i].abbr+'" class="menu">'+result.rows[i].abbr+' | </div>';

$(mymenu).appendTo('#menu');	
$("#"+result.rows[i].abbr).on('click',function(){

        alert("HELLO");
});

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
  • 2
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 39770982
Add this CSS :
#menu div.menu {
    display: inline-block;
}

Open in new window


or replace your div by span

Test page : http://jsfiddle.net/4zh3m/
0
 

Author Comment

by:1Cougar
ID: 39771045
Hi,

Thanks a lot.  In your example, you have

$("#menu div.menu").on('click', function(){
alert("HELLO");
});

Open in new window



Actually, I would like an onclick even for each menu item
onclick="doMenu(result.rows[i].id)" 

Open in new window

 
I tried to add it originally on the "mymenu" line but the onclick event never fired.  

With your method I think you are adding the "onclick" event after all of the text has been put in the menu, but I would like something different to occur for "en" and "fr"...

?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 2000 total points
ID: 39771070
$("#menu div.menu").on('click', function(){

var fr_or_en = $(this).text();

alert(fr_or_en);

});

Open in new window

0
 

Author Comment

by:1Cougar
ID: 39771398
Works great!  Thanks!

Cheers,
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

636 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