Obtaining a CSS element again to be utilized for boundary checking purposes

Is it possible to retrieve a CSS element?

I recently found myself in a situation where I needed to add some code to an Adobe Edge project, specifically involving the manipulation of margin-top and margin-left properties. While experimenting with moving an element named "woo", I struggled to call upon these elements within my custom code block. The code snippet provided successfully moves "woo" in different directions, but I'm unsure how to reference the margins when adding conditions like "sym.$("woo").css({"margin-left">0px"}) to the left movement code.

//Move RIGHT
if (e.which == 39) {
   sym.$("woo").css({"margin-left":"+=10px"});
}
//Move UP
else if (e.which == 38) {
    sym.$("woo").css({"margin-top":"-=10px"});
}
//Move Left
else if (e.which == 37) {
    sym.$("woo").css({"margin-left":"-=10px"});
}
//Move DOWN
else if (e.which == 40) {
    sym.$("woo").css({"margin-top":"+=10px"});
}

EDIT:

In an attempt to rectify the issue, I modified the Left conditional statement as follows:

else if (e.which == 37 && ($("woo").css("margin-left")>0)) {

While this seemed to partially resolve the problem, now the element refuses to move left altogether! I even tried using "<0" instead in case there was a mistake with the sign, but still no success achieving leftward movement.

ANSWER:

All things considered, I realized that returning values requires a slightly different syntax than initially anticipated. To retrieve the left margin value, rather than setting it with a dash as done previously, I had to use the following method.

sym.$("woo").css('marginLeft')

Subsequently, in order to convert the retrieved value into an integer for comparison, I utilized the following approach.

if(parseInt(sym.$("woo").css('marginTop'))>0)

Answer №1

To retrieve the value of a specific CSS property, you can utilize the .css() function:

$(...).css('padding-top')

Answer №2

It appears that I underestimated the syntax required for returning values. Instead of simply using a dash to retrieve the left margin as I had done previously, I had to adjust my approach as shown below.

sym.$("woo").css('marginLeft')

In order to convert it to an integer and compare it, I utilized the following method.

if(parseInt(sym.$("woo").css('marginTop'))>0)

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

What is the reason for using <div class="clear"></div> instead of <div class="clear"/>?

It dawned on me that: <div class="clear"/> can wreak havoc on the layout after a sequence of floating divs, whereas <div class="clear"></div> works perfectly fine. Does anyone have an explanation for this? Here is the CSS being used ...

JavaScript - Modify input character prior to appending it to the text area

I am working on creating a virtual keyboard using jQuery. Whenever I press 'a' in the textarea, I want it to display 'z' instead. In my investigation of typing a letter in the textarea, I discovered the following sequence: keyDown ev ...

Tips for incorporating a CSS transition when closing a details tag:

After reviewing these two questions: How To Add CSS3 Transition With HTML5 details/summary tag reveal? How to make <'details'> drop down on mouse hover Here's a new question for you! Issue I am trying to create an animation when t ...

Is the bootstrap navigation bar always hogging up valuable space?

Currently, I am diving into the world of react while also incorporating bootstrap styles. My current project involves creating a navigation bar using bootstrap, however, I'm facing an issue where the navbar is displaying in the middle rather than wher ...

What causes the content area of my <input> element to extend beyond the boundaries of its parent <span> element?

Please Note: I've been working on extracting code from a WordPress environment running the Salient theme. As of now, I haven't been able to simplify the issue to its core form. There is a possibility that I might figure it out myself, but I welco ...

What causes the shift in the position of the div element?

I have been struggling with a problem in my code. Whenever I hover over this element, it rotates as intended but it also changes its position. I can't figure out why this is happening. Can someone please help me debug this? I would greatly appreciate ...

adjusting array based on screen size fluctuations

Imagine having two arrays of images named landscape_images[] and portrait_images[]. One is for the landscape view and the other for the portrait view. When the screen width is in landscape mode, the wide resolution images will be displayed on the body. C ...

Attempting to simulate a camera shutter effect using div elements

I've been attempting to create a circular camera shutter, but I'm facing difficulties in making it look accurate. This is the desired outcome: https://i.sstatic.net/oS7gT.jpg The first 'petal' should be positioned lower than the last ...

Sorting table data by Table SubHeadings using Jquery

Utilizing jQuery tablesorter in my UI, I encountered a challenge with a table that has 2 rows of headers - one main header and one subheader. My goal is to enable sorting on the subheader. How can I achieve this? Below is an example of my code structure: ...

Utilizing the CSS Flex property to position one element in the center and align the other element to either the left or right side

What is the best approach to center one element inside a container with CSS flex properties and align another element to the left or right? Even when I set ChatGPT's recommendations of margin-left and margin-right properties to auto for the right-ali ...

The issue of AngularJS inline style color not functioning in Internet Explorer 11 has been identified

Hello, I am currently attempting to dynamically change the color of a p tag. However, I am facing issues with IE-11 not supporting this functionality. How can I resolve this problem? <p style="color:{{userData.color}} !important;">{{userData.someTex ...

Adjust the spacing between the inputRoot and input in Material UI Autocomplete

Recently, in one of my projects, I've been utilizing Material-UI's Autocomplete component. Despite its lack of flexibility with resizing, I managed to tweak certain width, height, and font size attributes successfully. However, I'm currently ...

Discover the method to retrieve HTML content by sending an HTTP POST request in AngularJS, similar to loading content

My attempt to retrieve HTML content using Angular Js Post HTTP method was successful, but only for text contents like P tags. I am now trying to fetch HTML contents that include input types such as text boxes using Angular JS. Interestingly, when I utilize ...

No content in Django's Bootstrap dropdown menu

I need assistance with extracting a list of objects and placing them in a dropdown menu. I have successfully achieved this, but the issue seems to be related to my HTML structure. Here is the code snippet from my HTML: <div class="dropdown"> < ...

How can I stop the CSS border of an iframe from flickering and what are some solutions to fix it?

I am encountering an issue with my iframe border when using CSS. The problem arises in Chrome where the border disappears upon resizing the page, while Safari changes the size (Firefox appears unaffected) https://i.sstatic.net/ZUi9z.gif Are there any kno ...

Tips for recognizing the div element housing the selected text chosen by the user

I am currently working on a feature that enables placing a button next to the text selected by the user. Here's what I want to achieve: However, I would like this functionality to apply only when the selected text is inside divs with the class floatb ...

What could be causing my Jquery fade effect to not function properly?

I'm new to incorporating Jquery into my website and I'm facing an issue with getting the first row of pictures to fade in (upwards) when scrolling. Despite my efforts, they are not behaving as expected. Any guidance on how to resolve this? HTML: ...

Printing in HTML is limited to only one page

While printing an HTML table that can vary in length, I often encounter the issue of it printing multiple pages. Is there a way to limit the printing to just one page through coding? Yes, you can achieve this by using the option in the browser print dialog ...

Incorporating a class into ever-changing Bootstrap Table rows

Looking to enhance my table rows with a class, excluding the header. Struggling to find a way to do this. Any ideas? This is the table in question: <table id="table" class="hidden table table-bordered table-striped table-hover"> <thead> ...

Disappear solely upon clicking on the menu

Currently, I am working on implementing navigation for menu items. The functionality I want to achieve is that when a user hovers over a menu item, it extends, and when they move the mouse away, it retracts. I have been able to make the menu stay in the ex ...