Solved

Build element dynamically

Posted on 2014-03-10
2
235 Views
Last Modified: 2014-03-10
I'm trying to build by own dialogue box (having lots of issues trying to customise the jQuery UI one to my requirements).  The idea is not to have any requiments on external CSS, HTML or Javascript, just call it and it will prepend to the page, and give me the ability to customise items such as border and size later.

I built it fine static proof of concept fine:-
http://jsfiddle.net/45kmB/

However when I tried to build it dynamically (so I can just call the function and everything is added to the document) it doesn't seem to work.
http://jsfiddle.net/tonelm2/J8WqS/1/

 I have minified my code only to display the overlay initially which I think is the issue:-
http://jsfiddle.net/tonelm2/as5xf/


When I look at the code after its been executed, all I get is:-

<div></div>

It doesnt seem to store any of the CSS values Ive been adding, which I belive should be added in:-
					$(testOverlay).css('display', 'inline')
						.css('height','1000px')
						.css('position', 'absolute')
						.css('width', '1000px') 
						.css('opacity', '0.40') 
						.css('filter', 'alpha(opacity=40)') 
						.css('background', '#000')
						.css('top', '0') 
						.css('left', '0')
						.css('cursor', 'wait');

Open in new window


However as far as Im aware I can chain the CSS statments like this.

Anyone have any idea what I'm doing wrong?
0
Comment
Question by:tonelm54
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39918479
Fixed up your code and just made your dynamic elements into objects e.g.
   
    var $testOverlay = $('<div/>');


http://jsfiddle.net/GaryC123/J8WqS/4/
0
 
LVL 16

Expert Comment

by:SriVaddadi
ID: 39918492
You seem to comment the below lines in the fiddle

    //$(testDialogue).prepend(testDialogueClose);
    //$(testDialogue).prepend(testDialogueTitle);
    //$(testDialogue).prepend(testDialogueBody);
    //$("body").append(testDialogue);

Hope its not the same case with your original code
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

by Julian Matz As of jQuery (http://jquery.com/) 1.4 the .live() method (http://api.jquery.com/live/) supports custom events as well as some standard JavaScript events that it previously didn't support. Among these is the submit event. Unlike …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

820 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