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 958753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:55:00+00:00 2026-05-16T00:55:00+00:00

I have some JavaScript code and a button which already has an event/action assigned

  • 0

I have some JavaScript code and a button which already has an event/action assigned to it, and I want to add a second event to the button. Currently the relevant bit of code looks like this:

   events: {onclick: "showTab('"+n+"')"}, 

How do I amend this code so that it also increases the ‘width’ property of a div with class=’panel’, by a fixed amount e.g. 50px?

EDIT:

I understand. Problem is I don’t know how to change id, only classname. The div is constructed in JavaScript using buildDomModel as follows:

  this.buildDomModel(this.elements["page_panels"],
        { tag: "div", className: "tab_panel",
          id: "tab_panel",
          childs: [...]}
 )

But the id doesn’t get changed to ‘tab_panel’. HOWEVER, classname does get changed to ‘tab_panel’ which is why i tried to use getelementbyclass. So the div has no id and I don’t know how to create one using the buildDomModel but I can give unique class. I have put the code in original post too.

  • 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-16T00:55:00+00:00Added an answer on May 16, 2026 at 12:55 am


    This:

    events: {onclick: "showTab('"+n+"'); $('div.panel').width('50px');"},
    

    Or you might want to add below line to showTab function.

    $('div.panel').width('50px');
    

    Update:

    Or you can do with vanilla javascript:

    function setWidth()
    {
       // since you are using a class panel, means more than one div, using loop
    
       var divs = document.getElementsByTagName('div');
    
       for(var i = 0; i < divs.length; i++)
       {
         // check if this div has panel class
         if (divs[i].getAttribute('class') === 'panel')
         {
            // set the width now
            divs[i].setAttribute('width', '50px');
         }
       }
    }
    

    Or if you want to apply the width to just one specific div, give that div an id and use this function instead:

    function setWidth()
    {
       var div = document.getElementById('div_id');
       div.setAttribute('width', '50px');
    }
    

    And later use it like this:

    events: {onclick: "showTab('"+n+"'); setWidth();"},
    

    Or you might want to add below line to showTab function.

    setWidth();
    

    Update 2:

    Ok modify the function like this:

    function setWidth()
    {
       var divs = document.getElementsByTagName('div');
    
       for(var i = 0; i < divs.length; i++)
       {
         // check if this div has panel class
         if (divs[i].getAttribute('class') === 'tab_panel')
         {
            // get previous width
            var prevWidth = getComputedWidth(divs[i]);
            // set the width now
            divs[i].setAttribute('width', (prevWidth + 50));
         }
       }
    }
    
    function  getComputedWidth(theElt){
            if(is_ie){
                    tmphght = document.getElementById(theElt).offsetWidth;
            }
            else{
                    docObj = document.getElementById(theElt);
                    var tmphght1 = document.defaultView.getComputedStyle(docObj, "").getPropertyValue("width");
                    tmphght = tmphght1.split('px');
                    tmphght = tmphght[0];
            }
            return tmphght;
    }
    

    Note that with jQuery it should be this code in all:

    function setWidth(){
      jQuery('.tab_panel').each(function(){
        jQuery(this).attr('style', 'width:' + (jQuery(this).width() + 50));
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code that dynamically creates a new button through JavaScript that when
I have some old javascript code from around 2000-2002 which (surprisingly) still works in
I have some javascript code which orginally checked/unchecked multiple checkboxes which was great. But
So I want to add some javascript to the onclick event of several controls
I have some PHP code which runs a loop, spitting out a button and
I have a print button with id=print_req . I wrote some Javascript code for
I have the javascript code below which disables an asp.net button during page postback.
I have some javascript code with do while outer loop and switch inner loop,
I have some Javascript code that will programmatically register an COM interop assembly by
I have some JavaScript code that works in IE containing the following: myElement.innerText =

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.