What is the best way to determine the value of margin-left in inline CSS using jQuery?

Here is the code snippet I am working with:

<div class="ongoing" style="width: +728px; margin-left: +12480px">

I need to extract the value of the margin-left property for scrolling purposes.

The technique I used to retrieve the width value does not work for margin-left due to the hyphen in its name. This was my attempt:

$("div.ongoing")[0].style.margin-left

Could someone provide guidance on how to access the margin-left value?

Many thanks!

Answer №1

To achieve this, you must utilize either of the following methods:

 document.querySelector("div.ongoing").style.marginLeft;

or

 $("div.ongoing").css("marginLeft");//or .css("margin-left");

Answer №2

Check it out: $('div.ongoing').attr('margin-left')

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

Error in processing JSON data due to numerical discrepancy

Recently, I have been working with a PHP class that uses AJAX to return data in JSON format. Here is an example of the data it returns: ["2016-02-08 09:00:00.000","2016-02-15 09:00:00.000"] However, when I try to use jquery.parseJSON(data), I'm enco ...

Installing Vue JavaScript using the npm command

Embarking on my journey as a Vue JS learner, I took the plunge to install Vue and delve into creating web applications using it. So, I globally added npm Vue. npm install --global vue-cli This action resulted in: npm WARN deprecated [email protected]: T ...

Utilize ng-repeat to iterate over two arrays

Two arrays are at my disposal here. The first array contains option content, while the second array consists of option tags (i.e., A, B, C, D). How can I structure the layout for the 'input type="radio"' using ng-repeat? To start off, I am attem ...

Adjust the appearance depending on the React state variable

I am trying to add animation to a search icon when clicked in React. Using the useRef hook, I am able to access the element and applying custom styles to it. const [searchBar, setSearchBar ] = useState(false); const searchIcon = useRef(); const searchIconS ...

Convert an array of objects into an object where the keys are determined by the value of a specific

I'm working with an array that looks like this: const inventory = [ { fruit: 'apple', quality: 'good', quantity: 10 }, { fruit: 'banana', quality: 'average', quantity: 5 }, { fruit: 'orange', qua ...

Using placeholders with inputs in an Angular2 table generated by ngFor

I have an array public example = [['hallo', 'fruit', 'rose'], ['apple','book']] Currently, I am working on creating a table of inputs. The values in this table depend on the specific part that I am usin ...

Creating an original list by iterating through a given list

I understand that some may consider this a duplicate, but I have yet to come across a similar example that I can relate to with my limited knowledge. So, I apologize in advance :) This should be pretty simple for an experienced JS developer, I assume. My ...

The conditional statement to check for an empty object does not trigger any actions

My goal is to display a success message once users successfully register without any errors. I have an errors reducer object in Redux that stores errors sent from the backend. The logic is set up so that if the errors object is empty, it shows the success ...

Having difficulty setting up multiple buttons to share the same function in jQuery using HTML

After clicking a button, my code dynamically adds content to a div and inserts buttons with names like "teamReq_"+index+"_AddYear" into the document (where index is a number retrieved from a hidden input field). If these buttons are spammed, multiple divs ...

What could be the reason for the failure of calling a function within an object using "this.myFunction"?

Reviewing these two code snippets, I am faced with a puzzle. The first code block fails to execute, while the second one successfully runs. This has left me perplexed, and I am seeking clarification from those who can shed some light on the matter. [My cu ...

Which tools should I combine with Angular for developing both Android and iOS applications?

My primary focus has been on developing web apps using Angular, but now I am interested in creating native Android and iOS apps with Angular. I have heard about using Cordova, Capacitor, and NativeScript for this purpose, as alternatives to Ionic due to pe ...

What is the best way to transform a one-dimensional object array into a two-dimensional array in a Vue component, based on a specific key?

My vue modules are structured like this: [types.GET_PRODUCT_CATEGORIES] (state,{ stores }) { state.product_categories = {} console.log(stores); stores.forEach(message => { set(state.product_categories, message.id ...

Struggling to make a click function function properly using ajax and php

Here is the code I am working with. I have successfully queried the database and displayed the results in JSON format at the top of the page. Now, I am trying to use a click function to display them again when a button is clicked later on the page, but I ...

Positioning the box in the middle of pages

I have a website page at the following link: However, the content is not centered on the screen. Here are the codes I'm using: <div class="section_inner"> <div class="container"> <div class="row"> <?ph ...

Trouble persists in saving local images from Multer array in both Express and React

I am having trouble saving files locally in my MERN app. No matter what I try, nothing seems to work. My goal is to upload an array of multiple images. Below is the code I have: collection.js const mongoose = require("mongoose"); let collectionSchema ...

Ensure that the next iteration of .each() does not begin until all nested functions have finished executing

Is there a way to ensure that my .each() function waits for all nested functions to complete before moving on? Here is the code I am working with: HTML: <div> <p>Text 1</p> <p>Text 2</p> <p>Text 3</p> & ...

Creating a Bootstrap layout with columns of varying heights

My current setup looks like this: <div class="row"> <div class="col-md-4">Content</div> <div class="col-md-4">Content</div> <div class="col-md-4">Content</div> <div class="col-md-4">Content&l ...

retrieve the coordinates of the northwest and southeast corners of a group of markers displayed on a Google Map

Is there a more efficient way to get the NE and SW corners of a set of markers on a Google map without iterating over each marker individually using JavaScript or Google functions? function fnSetBounds(){ var lowLat = 90; var highLat ...

What is the best way to eliminate the nesting in this ternary operation?

Object.values(filter).filter(item => (Array.isArray(item) && item.length > 0) || (typeof item === "boolean" && item === true) || (item !== null)).length ? filterIcon : unFilledIcon In this code, I aim to simplify the nested ternary operator and ...

combining the name of an array with a numeric value

I have several arrays, named array_1, array_2 through array_5. Based on a specific level, I aim to utilize an array. For instance, when level = 1, I want to use array_1. Attempting myArr = array_ + level results in myArr not being recognized as an array ( ...