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

  • Home
  • SEARCH
  • 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 8354047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:26:17+00:00 2026-06-09T09:26:17+00:00

I am using the following code: $(‘#dataTable .select-topic’) .click(function () { if ($(this).attr(‘data-list’) ==

  • 0

I am using the following code:

   $('#dataTable .select-topic')
        .click(function () {
            if ($(this).attr('data-list') == "N") {
                $(this).attr('data-list', 'Y')
                var topicSelectHtml = $('#TopicID')
                .clone()
                .find("optgroup:first").remove().end()
                .find("option[value$='**']").remove().end().html();
                $(this).html(topicSelectHtml);
                $(this).attr('data-clicked', 'Y')
            }
        })
        .change(function () {
            $(this).attr("title", $("option:selected", this).text());
            var type = $(this).attr('id').split('_')[1];
            updateField(entity, $(this), type);
        })

It’s applied to a few hundred rows as each row has a select. For efficiency would it be better for me to create named functions and attach these to the click and change. If so then how could I do this for the above code?

  • 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-06-09T09:26:19+00:00Added an answer on June 9, 2026 at 9:26 am

    Whether the function is named or not won’t really affect performance. Rather than creating and binding hundreds of different instances of the functions, however, it might be better to just create a delegated event handler once and bind that to the parent:

    $('#dataTable').on('click', '.select-topic', function() {
        if ($(this).attr('data-list') == "N") {
            $(this).attr('data-list', 'Y')
            var topicSelectHtml = $('#TopicID').clone().find("optgroup:first").remove().end().find("option[value$='**']").remove().end().html();
            $(this).html(topicSelectHtml);
            $(this).attr('data-clicked', 'Y')
        }
    }).on('change', '.select-topic', function() {
        $(this).attr("title", $("option:selected", this).text());
        var type = $(this).attr('id').split('_')[1];
        updateField(entity, $(this), type);
    });​
    

    This will handle clicks on the same elements, but with only a single function being bound, which will help performance.

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

Sidebar

Related Questions

I am using following code to show a spinning wheel: $(#loading) .hide() .ajaxStart(function(){ $(this).show();
I am using following code to get bitmap from url. This function is used
I am using following code to open a modalwindow: function OpenPopup(rn) { var winargs
Using following code: db.changes({'include_docs':true}).on('response', function (res) { res.on('data', function (change) { console.log(change); }); });
Using following code I try to get updated list of checkbuttons' corresponding text values,
I using following code: var search = 'test'; if ($('#sku').find(search) ){ //alert(search); $(document).find(search).css('color','red'); <TABLE>
i am using following code $doc = new DOMDocument(); $doc->strictErrorChecking = false; @$doc->loadHTML($data); $xpath
I created a DB using following code. Dim conn As New SqlConnection(Server=.\SQLExpress;Data Source=;Integrated Security=SSPI)
I am using following code to append param to url. This is working fine
I am using following code to get List from xml file - public static

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.