Disable the height property in the DOM when implementing the jQueryUI resizable feature

I'm utilizing the flex property to create a responsive layout for my web application.

In order to enable resizing of my navigator panel, I have implemented jQuery UI. However, upon triggering the resize event, jQuery UI is adding a hardcoded height to my element in the DOM, even when I specify the handles in the resizable settings.

When the resize event occurs, the following code is inserted into the DOM:

<div class="navigator ui-resizable" style="top: 0px; left: 0px; width: 245px; height: 929px;">

I am looking to remove all styles from the element except for the width.

Below is the code snippet for reference:

<!DOCTYPE html>
<html>
    <head>
        <style>

        html, body {
            margin: 0;
            height: 100%;
        }
        .mainWrapper_1
        {
          display: flex;
          background: gold;
          height: 100%;
        }

        .mainWrapper_1 .navigatorManager
        {
            background: tomato;
            flex: 0 0 30px;
        }

        .mainWrapper_1 .mainWrapper_2
        {
          background: gray;  
          flex: 1;
          display: flex;
          flex-direction: column;
        }

        .topSideBar
        {
            height: 50px;
            background: yellow;
        }
        .mainWrapper_3
        {
            flex: 1;
            background: cyan;
            display: flex;
        }
        .navigator
        {
            flex: 0 0 auto/*100px*/;
            background-color: green;
        }
        .mainWrapper_4
        {
            flex: 1;
            display: flex;
            flex-direction: column;
            background: red;
        }
        .tabs
        {
            height: 50px;
            background: pink;
        }
        .mainWrapper_5
        {
            flex: 1;
            background: magenta;
        }

        </style>
    </head>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.js"></script>
    <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/ui-lightness/jquery-ui.css">
    <body>
        <div class="mainWrapper_1">
          <div class="navigatorManager">side</div>
          <div class="mainWrapper_2">
            <div class="topSideBar">
              top side bar
            </div>
            <div class="mainWrapper_3">
                <div class="navigator">
                    navigator
                </div>
                <div class="mainWrapper_4">
                    <div class="tabs">
                        TABS
                    </div>
                    <div class="mainWrapper_5">
                        MAIN
                    </div>
                </div>
            </div>
          </div>
        </div>
    </body>

    <script>
        $(document).ready(function(){
            $(".navigator").resizable({handles: "e"});
        });
    </script>
</html>

Answer №1

If you want to make adjustments to the code, consider removing only the height attribute. The top and left attributes are responsible for positioning the .navigator element and are likely necessary for the resize feature to work properly. To remove an attribute, you can use the removeAttr() method in jQuery or the .removeAttribute() method in JavaScript. The code snippet below uses .removeAttr(), with the alternate usage of .removeAttribute() commented out. Simply switch the comment marks to apply the latter method.

Furthermore, it's worth noting some unusual placements in your code, such as...

  • ...the <script> tags positioned after the closing </body> tag.
    • <script> tags are typically placed within the <head> section after <link> and <style> tags. Alternatively, <script> tags can be located right before the closing </body> tag.

  • Additionally, there is a <link> tag situated outside of the <head> part.

    • Although placing a <link> tag outside of the head is permissible, it should ideally be positioned as high as possible in the HTML structure (preferably within the head, following any <meta> tags). This ensures that the browser renders styles consistently and promptly, thereby optimizing the rendering process.

       $(document).ready(function() {
           $(".navigator").resizable({
                 handles: "e"
            }).removeAttr('height');
          //document.querySelector('.navigator').removeAttribute('height');
       }); 
      

Check out the Live Demo: PLUNKER

SNIPPET

<!DOCTYPE html>
<html>
        <head>
        <meta charset='utf-8'>
        <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.4/themes/dark-hive/jquery-ui.css">
        <style>
html, body { margin: 0; height: 100%; }
.extLayer { display: flex; backgound: gold; height: 100%; }
.extLayer .navMgr { background: tomato; flex: 0 0 30px; }
.extLayer .endoLayer { background: gray; flex: 1; display: flex; flex-direction: column; }
.topSideBar { height: 50px; background: yellow; }
.intLayer { flex: 1; background: cyan; display: flex; }
.navigator { flex: 0 0 auto/*100px*/; background-color: green; }
.auxLayer { flex: 1; display: flex; flex-direction: column; background: red; }
.tabs { height: 50px; background: pink; }
.coreLayer { flex: 1; background: magenta; }
</style>
        </head>

        <body>
<div class="extLayer">
          <nav class="navMgr">side</nav>
          <div class="endoLayer">
    <header class="topSideBar"> top side bar </header>
    <div class="intLayer">
              <nav class="navigator"> navigator </nav>
              <section class="auxLayer">
        <div class="tabs"> TABS </div>
        <main class="coreLayer">
                  MAIN
                </main>
      </section>
            </div>
  </div>
        </div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script>
        $(document).ready(function(){
            $(".navigator").resizable({handles: "e"}).removeAttr('height');
//document.querySelector('.navigator').removeAttribute('height');
        });
    </script>
</body>
</html>

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

Refreshing the page is the only way to activate the jQuery function

I am currently using the $.getJSON(...) method to fetch JSON data (images) for my HTML web page. The getJSON() function is triggered once the DOM has fully loaded: $(document).ready(function() { Subsequently, I am utilizing the montage.js library to orga ...

Determining Asynchrony in Node.js Through Programming

Is there a way to assess if a function can be executed asynchronously without requiring a callback? I am currently working with Node.js on the Intel Edison platform and utilizing mraa. The native C++ functions like i2c.readReg(address) do not have provisi ...

Ways to make <li> elements display inline with React Bootstrap Rows and Columns

I have some content that I need to format and display in a horizontal list. When I only use HTML elements in the list, it appears horizontally as expected. However, when I incorporate React Bootstrap grid layout components like Row and Column, the list dis ...

Manipulating strings within strings with JavaScript

It's been a strange discovery I made while working with JavaScript. Whenever I try to assign a two-word string to a CSS property, like setting the fontFamily property of an HTML element to "Arial Black", it ends up looking something like thi ...

Failed PHP response when jQuery was called

I'm working on a project that involves two files: one PHP and one HTML. The HTML file acts as the user interface where users input their queries, while the PHP file handles the processing and events before returning the output back to the HTML file. I ...

Exploring Three.js on Cordova with WebGL

I am working on developing a mobile app using Three.js on Cordova. While the app runs smoothly on a PC browser, it encounters an issue when trying to create the WebGL context on a Samsung Note 3 device. The specific error message is: THREE.WebGLRenderer ...

Creating pagination using AJAX to fetch data from an API while maintaining the same query parameters

Writing a title for this may be a bit tricky, but I'll try my best. On the webpage located at the /music-maker endpoint, there is a modal that contains an input field. This input field captures user input and sends it to the backend using AJAX. The u ...

Adjusting the visible options in ngOptions causes a disruption in the selected value of the dropdown menu

I have successfully implemented a feature that allows users to convert temperature values displayed in a drop-down menu to either Celsius or Fahrenheit. For this functionality, I am using a select input with ng-options as shown below: <select ng-model ...

What is the method for establishing session or cookie in an HTTPS request to a specific URL?

When making an HTTPS GET request in Node.js to a specific URL, it is necessary to include the session cookie. In this case, I already have the value of the cookie that needs to be sent. var URL = require('url-parse'); var appurl = "https://test ...

Tips for positioning elements within an ng-repeat list using absolute positioning?

Here is the HTML code: <div class = "container"> <form ng-submit = "createSticky()"> <input ng-model="formData.data" type="textarea" name="sticky_content" placeholder="add sticky text" required="true"/> <input ng-model= ...

When sending an ajax request with HTML data as the payload

While working on an MVC program, I encountered an issue when trying to send data from a TextArea to the controller upon a button click. Everything worked fine until I had HTML-based data inside the TextArea. Here's a snippet of the HTML code: <te ...

Guide to filling a dropdown menu by aligning with the text it contains?

I've set up two dropdown select boxes below that are exactly the same: HTML <select id="ddl1" name="ddl1"> <option value="1">TEXT 1</option> <option value="2">TEXT 2</option> <option value="3">TEXT 3&l ...

What should I do when using _.extend() in express - override or add in fields?

When an object is extended by another object with values set for some of the extended fields, will it be rewritten or will the new values be added? For example: const PATCH_REQUEST_SCHEMA = { 'type': 'object', 'title' ...

What steps can I take to resolve the warning about serving images with low resolution in Lighthouse while using Next.js?

I successfully incorporated the svg logo into my webpage using the Next.js Image tag. import Image from "next/Image" export default function Home() { return ( <div> <Image width={32} height={32} src="/logo.svg"> ...

Error: Unable to locate module '@material/core/Grid'

After cloning a repository that is built with MUI, I noticed that certain components were already imported and working seamlessly. These components include: import Card from '@mui/material/Card' import CardActions from '@mui/material/CardAct ...

What is the purpose of defining the initialState in Redux?

As per the Redux documentation, it is considered a best practice to establish an initialState for your reducer. However, maintaining this initialState can become challenging when the state relies on data from an API response, leading to discrepancies betwe ...

What is the hostname that npm install directs to?

My task is to set up multiple Node.js packages using npm on a standalone server that does not have direct internet access. I am able to specify an IP Address and port for access. When executing 'npm install' from the command line, where can I f ...

Exploring the world of cookie security with SameSite and Secure features in ExpressJS

Despite having the specified settings on my express application, a warning keeps appearing in the console. Has anyone encountered this error before? I found some information related to it here: https://github.com/expressjs/express/issues/3095 The version ...

How can I code a div to automatically scroll to the top of the page?

I'm attempting to implement something similar in WordPress - I want a div containing an advertisement to initially start 300px down the page, then scroll up with the page until it reaches the top, and finally stay there if the user continues to scroll ...

Adjust the tally of search results and modify the selection depending on the frequency of the user's searches within an array of objects

Seeking assistance with adding a new function that allows users to navigate to the next searched result. Big thanks to @ggorlen for aiding in the recursive search. https://i.stack.imgur.com/OsZOh.png I have a recursive search method that marks the first ...