Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How To Reference a Dynamic DOM Object From JS

 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following js return an Error:

"left" is null or Not an Object

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The lack of context in your post is breath-taking.

Did you inspect the contents of position after statement 8?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://api.jquery.com/position/

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1619
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I moved the DIV tag to the parent form and it now consistantly displays regardless of scroll.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic