How do I overwrite this calculation using JQuery?

I have a website:

link

There are two pages on my site that have the same div elements... I want one page to perform a certain calculation on the divs, and another page to perform a different calculation...

New JavaScript Code:

jQuery(document).ready(function ($) {

    var windowsizecontact = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
    console.log("screen contact:",windowsizecontact);
    var stanga= jQuery('.contact-stanga').outerWidth();
    console.log("left side:",stanga);  
    var dreapta= jQuery('.contact-dreapta').outerWidth();  
    console.log("right side:",dreapta);  
    var contentcontactwh=windowsizecontact-stanga-dreapta;
    console.log("result",contentcontactwh);
    $('.contact-container #primary').css{('cssText', contentcontactwh'!important')};   //here I want to override this div

});

This is the old code (which should only apply to specific pages)

jQuery(document).ready(function ($) {
    var width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
    var leftSide = jQuery('#secondary').outerWidth();
    var selected = jQuery('.selected').outerWidth();
    var calculation = width - leftSide - selected;
    $('#primary').css('width', calculation);

});

My issue is that the new code above does not affect the div on the contact page because of the old code... and I need it to be unique. (The old code must still exist)

Is there a way to override this somehow?

EDIT:

jQuery(document).ready(function ($) {

  var windowsizecontact = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  console.log("screen contact:",windowsizecontact);
  var stanga= jQuery('.contact-stanga').outerWidth();
  console.log("left side:",stanga);  
  var dreapta= jQuery('.contact-dreapta').outerWidth();  
  console.log("right side:",dreapta);  
  var contentcontactwh=windowsizecontact-stanga-dreapta;
  console.log("result",contentcontactwh);
  console.log("------------------");



  if ($("#primary").hasClass("content-contact")) {
     alert("ggg");
      $('.content-contact').css("width:",contentcontactwh); //the issue lies here now

  }else
  {
  var width = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  var leftSide = jQuery('#secondary').outerWidth();
  console.log("left side:",leftSide);
  var selected = jQuery('.selected').outerWidth();
  console.log("left side:",leftSide); 
  var calculation = width - leftSide - selected;
  $('#primary').css('width', calculation);
   }

});

I tried the first suggestion given... but now the div width is not being applied correctly.

Did I make a mistake in the syntax?

Answer №1

let myApp = myApp || {};

myApp.initialFunction = function () {
    // default code
};

// When needed, update the code on the website
myApp.updatedFunction = function () {
    // updatedCode
};

// Make sure to call the function when the document is ready
$(function () {
    myApp.initialFunction();
});

Answer №2

If everything else is functioning correctly and the issue lies solely in this particular line, then let's make a slight modification to it.

Here is the code snippet:

  $('.content-contact').css("width:",contentcontactwh); //try removing the : after width

Change it to:

  $('.content-contact').css("width",contentcontactwh); 

If the problem persists, please provide the console error message for further investigation.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Assign a unique CSS style to each Popper

I am currently working on a component that generates 6 unique experiences, each with its own popper. My goal is to customize the styles of each popper in terms of background and position, and ensure that all poppers display images of the same size. Despite ...

What could be the reason for JavaScript code successfully exporting to Excel using the old office extension .xls but encountering issues when trying to export

I am currently working on exporting an HTML table to Excel using JavaScript. I have encountered an issue where it does not export to the newer version of Excel with the xlsx extension. However, it works fine and exports to older versions of Excel with the ...

Calculate the total rows within a specified date range

Within my database, there is a column named IsStaff, which returns a value as a bit. This signifies whether a staff member in a company has an illness (1) or not (0). How can I construct an SQL query to count the occurrences of both 1's and 0's w ...

What is the best location to include my JavaScript code in WordPress?

Alright, so I've got this world map on one of my WordPress pages and here's an example of the code: <area onmousedown="modifyImage('world_map_01', './images/map/asia.jpg')" onmouseout="modifyImage('world_map_01', ...

Is it possible to utilize Vue's splice method within a forEach loop in order to delete multiple elements at

I am currently working on an image grid in array form. I am trying to implement a multi-deletion functionality. When a checkbox for each image in the grid is checked, I store the selected image's index in an array called selectedImages. Upon clickin ...

Make IE10 HTML page use IE Quirks mode

Assist me, I'm battling with Internet Explorer. We have a series of pages that function well in IE8 (on our intranet). The company has made the decision to upgrade directly to IE10. What is the HTML code needed to force a page to use IE5 Quirks Mode ...

SwiperJS continuously applies additional right margin to every slide

My Swiper carousel seems to be adding an unnecessary 5px margin-right to each slide, resulting in the cards not fitting into one frame. I attempted to fix this by setting the margin-right to 0px for the .swiper-slide class using !important, but it didn&ap ...

Transmitting a pair of data points to PHP using ajax POST for querying the SQL database

I am attempting to send two values from a form to another PHP file using the ajax post method. One value is the current input box value, while the other is the value being typed into a different input box which functions as a search box. When I execute the ...

Trying to open the DB URL in a new tab when using PHP and MySQL will not work as expected

Before I begin, I want to express my gratitude to the community of StackOverFlow users for providing valuable answers. As a novice in PHP/mySql, I am learning through books and examples from others. Currently, my issue revolves around a MySQL database wit ...

Using AngularJS to interact with resources by passing in the scope parameter

My issue is as follows: I am attempting to call a resource with a specific parameter, but I keep encountering the following error: [$resource:badcfg] I have spent the last 3 hours trying to resolve this, but to no avail. When I call the resource like th ...

Executing an Ajax PUT request on a select_tag element

I am currently working on a project where I have implemented a DropDown Menu in my View. This DropDown Menu has a Callback that triggers as soon as it detects the change event. My goal is to pass the selected value from the DropDown to my Line_items contro ...

The art of placing images using CSS

I'm having trouble aligning the images into two rows of three, with the news section on the right side below the navigation bar. I've tried different methods but can't seem to get it right. Both the image and link should be clickable, but I& ...

How can I redirect applications from a web browser to Safari?

Is there a way to redirect applications from a browser to Safari? For Android devices, I have implemented a feature where if a user opens my site through a browser built-in within apps like Facebook or Telegram, they are automatically redirected to Google ...

Embedding CSS stylesheets in a Django template

I'm currently working on a large Django website and in the process of adding the HTML templates. Here is the file tree for the main part: C:. +---forums | | admin.py etc | | | +---migrations | | | ... | | | +---templa ...

Ways to remove all HTML elements from a string

Check out the code that I currently have: I am looking for a way to prevent users from entering any HTML tags in the "Add Responsibilities" field. For example, if a user enters the following: <div>Test</div> It should only display the text l ...

Determine if a certain value is present in an array within an HTML document

In the context of AngularJS, I have an array that looks like this: var test=["abc/1/1","def/2/2","efg/3/3"]; I am trying to determine if the array contains a value with "abc" in it within my HTML code. When I used the following: test.indexOf("abc")!=-1 ...

javascript, issues with floating and displaying elements

I am currently working on creating a JavaScript menu that has a click function to smoothly slide up and down. Although the JavaScript code appears to be functioning correctly, it seems that there is some interference with the CSS. Despite attempting vario ...

Creating a response in Node JS

I'm struggling with crafting a response to the server. Currently, I have a login form that sends data to the server. On the backend, I verify if this data matches the information in a .json file and aim to send a response upon successful validation. ...

Smooth animation is not being achieved with the Jquery dlmenu

I have implemented a multi-level navigation menu using a demo of the jquery dlmenu plugin v1.0.2. Although most of the functions are working smoothly, the CSS3 menu navigation lacks the fluidity of the jQuery left/right sliding effect. Is there a way to ...

Different method of including the ng-click attribute on the body element

Greetings! I am currently developing a chrome extension and incorporating Angular to prevent any conflicts with other Angular pages. To avoid conflicts, I am attempting to set an ng-click on the body element. Here is the code snippet I used: var body = do ...