*
The moose likes HTML, CSS and JavaScript and the fly likes How To Reference a Dynamic DOM Object From JS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How To Reference a Dynamic DOM Object From JS" Watch "How To Reference a Dynamic DOM Object From JS" New topic
Author

How To Reference a Dynamic DOM Object From JS

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
The following js return an Error:

"left" is null or Not an Object

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

The lack of context in your post is breath-taking.

Did you inspect the contents of position after statement 8?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

P.S. If you are already using jQuery, why are you setting the position styles by hand rather than using jQuery?
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Bear Bibeault wrote:P.S. If you are already using jQuery, why are you setting the position styles by hand rather than using jQuery?


The truth is and you already know it is "I have no idea what I am doing!" Every day is a challenge. I look up code to attemp to accomplish what I need, I study the class explanations, I really try. I am just plain confused. This code I am trying to use was taken from a jQuery example so I thought I was using jQuery, guess I have a mixture. Can you give me some help here.

I seems like the code is not recognizing that the following is an object in the DOM.



Then the example I found listed the code as the following as a reference to the DOM object but that does not work either:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Steve Dyke wrote:Then the example I found listed the code as the following as a reference to the DOM object but that does not work either:


That code does not assign the DOM element to p, it creates a jQuery wrapped set of the element.

If you want to obtain a direct reference to the DOM element from the wrapped set use one of:
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Bear Bibeault wrote:
Steve Dyke wrote:Then the example I found listed the code as the following as a reference to the DOM object but that does not work either:


That code does not assign the DOM element to p, it creates a jQuery wrapped set of the element.

If you want to obtain a direct reference to the DOM element from the wrapped set use one of:


I hate to keep bothering you but I still am having trouble. The first alert returns 4.0 the value of the DOM object I am referencing so I know the object exists. The second alert return undefined.

By the way have I got my position code correct now using jQuery correctly?

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

This is confusing me:



In the first bit you are getting an element with an ID of wRow + "quickeditQty". In the second bit you are getting an element with an ID of "dcnote". Are you attempting to get the same element in both of these examples? If so, you need to just use $('#'+dcnote). Also, getting the value of an element and getting the element itself are 2 different things.



should be what you want, assuming you are trying to duplicate the first bit using jquery.


GenRocket - Experts at Building Test Data
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Gregg Bolinger wrote:This is confusing me:



In the first bit you are getting an element with an ID of wRow + "quickeditQty". In the second bit you are getting an element with an ID of "dcnote". Are you attempting to get the same element in both of these examples? If so, you need to just use $('#'+dcnote). Also, getting the value of an element and getting the element itself are 2 different things.



should be what you want, assuming you are trying to duplicate the first bit using jquery.


No what I want is the position of the DOM element with the ID of wRow + "quickeditQty";

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

http://api.jquery.com/position/

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

Alerts are a horrible way to debug. Grab ahold of Firebug and use console.log() and console.dir() to emit debug statements to the JavaScript console.

No what I want is the position of the DOM element with the ID of wRow + "quickeditQty";


Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

By the way, Bear and I are both correct. Depending on which type of position you need, you can use either .position() or .offset(). The API will describe when to use which.
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Gregg Bolinger wrote:By the way, Bear and I are both correct. Depending on which type of position you need, you can use either .position() or .offset(). The API will describe when to use which.


This is working now "Except" when I scroll the page the DIV is not displayed in the expected location. It is either higher or lower than expected.

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
I moved the DIV tag to the parent form and it now consistantly displays regardless of scroll.
 
 
subject: How To Reference a Dynamic DOM Object From JS