• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How To Reference a Dynamic DOM Object From JS

 
Ranch Hand
Posts: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following js return an Error:

"left" is null or Not an Object

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://api.jquery.com/position/

 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2206
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I moved the DIV tag to the parent form and it now consistantly displays regardless of scroll.
reply
    Bookmark Topic Watch Topic
  • New Topic