Home

Results 1 to 6 of 6

Thread: Accessing DOM element within a function

Hybrid View

  1. #1
    Join Date
    Feb 2008
    Posts
    37

    Accessing DOM element within a function

    I have an HTML form control with basically the example for a table in
    the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    table with id='example', but it is not working.

    Tried $('#example').dataTable();


    What am I missing?

    IDM 4.0.2 Patch C

    Thank you


    Daryl

  2. #2
    Wolfgang Schreiber NNTP User

    Re: Accessing DOM element within a function

    Daryl,

    $('#example') should give you a handle to the table object - verify with
    something like
    alert( $('#example').length );

    If you are referring to the external "dataTable" library you may need to
    include that 3rd party library with your form.

    Wolfgang


    On 02.01.2014 20:20, Daryl Creedy wrote:
    > I have an HTML form control with basically the example for a table in
    > the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    > table with id='example', but it is not working.
    >
    > Tried $('#example').dataTable();
    >
    >
    > What am I missing?
    >
    > IDM 4.0.2 Patch C
    >
    > Thank you
    >
    >
    > Daryl


  3. #3
    Join Date
    Feb 2008
    Posts
    37

    Re: Accessing DOM element within a function

    On 1/2/2014 3:06 PM, Wolfgang Schreiber wrote:
    > Daryl,
    >
    > $('#example') should give you a handle to the table object - verify with
    > something like
    > alert( $('#example').length );
    >
    > If you are referring to the external "dataTable" library you may need to
    > include that 3rd party library with your form.
    >
    > Wolfgang
    >
    >
    > On 02.01.2014 20:20, Daryl Creedy wrote:
    >> I have an HTML form control with basically the example for a table in
    >> the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    >> table with id='example', but it is not working.
    >>
    >> Tried $('#example').dataTable();
    >>
    >>
    >> What am I missing?
    >>
    >> IDM 4.0.2 Patch C
    >>
    >> Thank you
    >>
    >>
    >> Daryl

    The code below is in the HTML content field of the control:

    (function () {return "<table id='example'><thead><tr><th>Row
    1</th><th>Row
    2</th></tr></thead><tbody><tr><td>One</td><td>Two</td></tr><tr><td>Three</td><td>Four</td></tr></tbody></table>";}
    ) ();

    inline script:
    //Set Table to Jquery Data Table
    $(document).ready(function() {

    alert($('#example').length);
    });

    alert returns 0 for the length.

    Thank you

  4. #4
    Wolfgang Schreiber NNTP User

    Re: Accessing DOM element within a function

    Could it be a timing issue and the HTML table not yet be loaded when the
    jQuery executes?
    You could for example check this from a manually triggered onchange event.

    For debugging, the Firefox plugin firebug will show the dynamically
    generated HTML code of your loaded form.

    Wolfgang


    On 02.01.2014 21:22, Daryl Creedy wrote:
    > On 1/2/2014 3:06 PM, Wolfgang Schreiber wrote:
    >> Daryl,
    >>
    >> $('#example') should give you a handle to the table object - verify with
    >> something like
    >> alert( $('#example').length );
    >>
    >> If you are referring to the external "dataTable" library you may need to
    >> include that 3rd party library with your form.
    >>
    >> Wolfgang
    >>
    >>
    >> On 02.01.2014 20:20, Daryl Creedy wrote:
    >>> I have an HTML form control with basically the example for a table in
    >>> the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    >>> table with id='example', but it is not working.
    >>>
    >>> Tried $('#example').dataTable();
    >>>
    >>>
    >>> What am I missing?
    >>>
    >>> IDM 4.0.2 Patch C
    >>>
    >>> Thank you
    >>>
    >>>
    >>> Daryl

    > The code below is in the HTML content field of the control:
    >
    > (function () {return "<table id='example'><thead><tr><th>Row
    > 1</th><th>Row
    > 2</th></tr></thead><tbody><tr><td>One</td><td>Two</td></tr><tr><td>Three</td><td>Four</td></tr></tbody></table>";}
    > ) ();
    >
    > inline script:
    > //Set Table to Jquery Data Table
    > $(document).ready(function() {
    >
    > alert($('#example').length);
    > });
    >
    > alert returns 0 for the length.
    >
    > Thank you


  5. #5
    Join Date
    Feb 2008
    Posts
    37

    Re: Accessing DOM element within a function

    On 01/02/2014 05:20 PM, Wolfgang Schreiber wrote:
    > Could it be a timing issue and the HTML table not yet be loaded when the
    > jQuery executes?
    > You could for example check this from a manually triggered onchange event.
    >
    > For debugging, the Firefox plugin firebug will show the dynamically
    > generated HTML code of your loaded form.
    >
    > Wolfgang
    >
    >
    > On 02.01.2014 21:22, Daryl Creedy wrote:
    >> On 1/2/2014 3:06 PM, Wolfgang Schreiber wrote:
    >>> Daryl,
    >>>
    >>> $('#example') should give you a handle to the table object - verify with
    >>> something like
    >>> alert( $('#example').length );
    >>>
    >>> If you are referring to the external "dataTable" library you may need to
    >>> include that 3rd party library with your form.
    >>>
    >>> Wolfgang
    >>>
    >>>
    >>> On 02.01.2014 20:20, Daryl Creedy wrote:
    >>>> I have an HTML form control with basically the example for a table in
    >>>> the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    >>>> table with id='example', but it is not working.
    >>>>
    >>>> Tried $('#example').dataTable();
    >>>>
    >>>>
    >>>> What am I missing?
    >>>>
    >>>> IDM 4.0.2 Patch C
    >>>>
    >>>> Thank you
    >>>>
    >>>>
    >>>> Daryl

    >> The code below is in the HTML content field of the control:
    >>
    >> (function () {return "<table id='example'><thead><tr><th>Row
    >> 1</th><th>Row
    >> 2</th></tr></thead><tbody><tr><td>One</td><td>Two</td></tr><tr><td>Three</td><td>Four</td></tr></tbody></table>";}
    >>
    >> ) ();
    >>
    >> inline script:
    >> //Set Table to Jquery Data Table
    >> $(document).ready(function() {
    >>
    >> alert($('#example').length);
    >> });
    >>
    >> alert returns 0 for the length.
    >>
    >> Thank you


    I think it may have more to do with the fact the table is created inside
    the anonymous function call. Using firebug and just the function call
    to create the table, the table only shows up within the function call.

    I can call getElementByID, but I need a jQuery reference, I have tried
    different ways to convert but have had no success.

    Daryl

  6. #6
    Wolfgang Schreiber NNTP User

    Re: Accessing DOM element within a function

    If you can find the node with getElementByID, you'll also find it with
    jQuery. However, your jQuery event wrapper $(document).ready() may fire
    too early, so try without that from another event.

    Wolfgang


    On 03.01.2014 02:51, Daryl Creedy wrote:
    > On 01/02/2014 05:20 PM, Wolfgang Schreiber wrote:
    >> Could it be a timing issue and the HTML table not yet be loaded when the
    >> jQuery executes?
    >> You could for example check this from a manually triggered onchange
    >> event.
    >>
    >> For debugging, the Firefox plugin firebug will show the dynamically
    >> generated HTML code of your loaded form.
    >>
    >> Wolfgang
    >>
    >>
    >> On 02.01.2014 21:22, Daryl Creedy wrote:
    >>> On 1/2/2014 3:06 PM, Wolfgang Schreiber wrote:
    >>>> Daryl,
    >>>>
    >>>> $('#example') should give you a handle to the table object - verify
    >>>> with
    >>>> something like
    >>>> alert( $('#example').length );
    >>>>
    >>>> If you are referring to the external "dataTable" library you may
    >>>> need to
    >>>> include that 3rd party library with your form.
    >>>>
    >>>> Wolfgang
    >>>>
    >>>>
    >>>> On 02.01.2014 20:20, Daryl Creedy wrote:
    >>>>> I have an HTML form control with basically the example for a table in
    >>>>> the DG pro doc 5.5.15. I am trying to get a jquery reference to the
    >>>>> table with id='example', but it is not working.
    >>>>>
    >>>>> Tried $('#example').dataTable();
    >>>>>
    >>>>>
    >>>>> What am I missing?
    >>>>>
    >>>>> IDM 4.0.2 Patch C
    >>>>>
    >>>>> Thank you
    >>>>>
    >>>>>
    >>>>> Daryl
    >>> The code below is in the HTML content field of the control:
    >>>
    >>> (function () {return "<table id='example'><thead><tr><th>Row
    >>> 1</th><th>Row
    >>> 2</th></tr></thead><tbody><tr><td>One</td><td>Two</td></tr><tr><td>Three</td><td>Four</td></tr></tbody></table>";}
    >>>
    >>>
    >>> ) ();
    >>>
    >>> inline script:
    >>> //Set Table to Jquery Data Table
    >>> $(document).ready(function() {
    >>>
    >>> alert($('#example').length);
    >>> });
    >>>
    >>> alert returns 0 for the length.
    >>>
    >>> Thank you

    >
    > I think it may have more to do with the fact the table is created inside
    > the anonymous function call. Using firebug and just the function call
    > to create the table, the table only shows up within the function call.
    >
    > I can call getElementByID, but I need a jQuery reference, I have tried
    > different ways to convert but have had no success.
    >
    > Daryl


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •