Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6178329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:26:14+00:00 2026-05-24T00:26:14+00:00

Description By design most jquery code leads to a lot of tight coupling, e.g.

  • 0

Description

By design most jquery code leads to a lot of tight coupling, e.g. selectors assume a specific structure of html

var mySubnav = $("#navigation a.sub-menu");

If the corresponding html changes, for whatever reasons,

<a class="subMenu" .... </a>

functionality is broken.

Question

  • What’s the best way to handle tight coupling?
  • What approaches exist to loosen it up?

Answers, Approaches

  • use the html custom data attribute to separate css from js logic. e.g. add data-submenu="true" on the html and use var mySubnav = $("[data-submenu]"); on the js side.
  • implement a solid testing environment
  • couple as loose as possible, by using the least specific selectors, e.g. $("a.sub-menu'). See also
  • Eliminate the actual string literals that represent CSS selectors from the body of your jQuery code by (1) retrieving references to static DOM elements beforehand, and (2) storing selector strings in one place (at the top of your code).
  • use javascript frameworks, like Backbone, which decouple javascript from the DOM via views
  • use delegate and live regarding coupling due to event management
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:26:15+00:00Added an answer on May 24, 2026 at 12:26 am

    Use Custom prefixed classes for UI hooks ui-specificGuy

    Provided HTML

    <div class="container grid8">
        <ul class="ul1 horizontal">
            <li>List Item 1</li>
            <li>List Item 2</li>
        </ul>
    </div>
    

    Bad – using style purposed classes/hooks

    $('.container.grid8').stuff();
    $('.ul1.horizontal').moreStuff();
    

    Adjusting the HTML

    <div class="container grid8 ui-specificContainer">
        <ul class="ul1 horizontal ui-specificList">
            <li>List Item 1</li>
            <li>List Item 2</li>
        </ul>
    </div>
    

    Good – using your own purposed classes/hooks

    $('.ui-specificContainer').stuff();
    $('.ui-specificList').moreStuff();
    

    Only be as specific as neccessary

    If this will accomplish your goal.

    $('.ui-targetedElement')
    

    Then why have a selector that looks like this?

    $('ul > li a.ui-targetedElement')
    

    This simply introduces unnecessary DOM structure dependencies into the functionality you are building, and you should be able to be proactive in this regard because you should be providing your own hooks (prefixed classes) at this point right?

    Ultimately though I would say that tight coupling between the DOM and the script are sometimes unavoidable because of the nature of how they work together.

    Full Article

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know what is usual mediator design pattern (some description is in wikipedia: http://en.wikipedia.org/wiki/Mediator_pattern
I have a design question. I have a nested repeater structure that is 4
I'm design Elements with UiBinder, but I cant find a description of the property
Here is the problem description of my design. There is a class A (Singleton)
Here's my database design: USER SKILLS id idUser email 1-------* description name selfAssesedLevel lastname
I have an SQL table with the following design: TableSchedule: Id Description ImportedDate I
I need to design a search form and the code behind it. I'm not
Description | A Java program to read a text file and print each of
Description: An unhandled exception occurred during the execution of the current web request. Please
The description of DTDs in the XML 1.1 specification is very terse, and it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.