jQWidgets Forums

jQuery UI Widgets Forums General Discussions How to check widget creation on element

This topic contains 1 reply, has 2 voices, and was last updated by  Peter Stoev 8 years, 6 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • How to check widget creation on element #90282

    bb1769
    Participant

    Is there a way to check whether a JQ widget has already been created on an element? We have a site where the user shifts between different parts of the site, and when they enter one part it creates a jqxSwitchButton. If they leave that part, but then re-visit the section, it recreates the button, including adding a change handler. The issue then is that after the second visit, the handler is called twice (or multiple times with successive visits).

    I could create separate code to track button creation, but it’d be simpler code-wise to just check whether a widget is already attached to the element.

    EDIT: I realized that I can check for the classes on the element, like

    if (!$("#myElement").hasClass("jqx-widget")) {
    

    // create the widget
    `}

    Is this reliable or is there a better way?

    How to check widget creation on element #90284

    Peter Stoev
    Keymaster

    Hi bb1769,

    jqx-widget is available for all widgets, yes. However, I would suggest you to re-think whether this is really required.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.