[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Build element dynamically

Posted on 2014-03-10
2
Medium Priority
?
246 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
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…
Suggested Courses
Course of the Month19 days, 15 hours left to enroll

872 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