The parent element is not able to apply the CSS text-decoration in jQuery

Is there a way to retrieve a specific CSS property of an element, even if it is inherited from its parent?

The standard jQuery method .css() can help with this.

Consider the following HTML structure:

<div id="container"> some text<br>
        <span id="some">Our element</span>
   <br> some text
</div>

<div id="result">
</div>

Defined CSS styles:

#some {
    font-weight:bold;
}

#container {
    text-decoration: underline;
    color: rgb(0,255,0);
    font-size: 32px;
}

and jQuery script:

$(function() {
    var decor = $("#some").css('text-decoration');
    var weight = $("#some").css('font-weight');
    var color = $("#some").css('color');
    var size = $("#some").css('font-size');
    var result = "<br><b>our object's own property:</b>"
    result += "<br>font-weight:" + weight + "<br>";
    result += "<br><b>inherited properties:</b><br>";
    result += "color: " + color + "<br>font-size: " + size + "<br>text-decoration: " + decor;

    $("#result").html(result);
});

All CSS properties are displayed except for text-decoration. Want to know why? http://jsfiddle.net/aQYs2/

Answer №1

The css-specification states that text-decoration is defined with Inherited:no, while the other properties in your example are defined with Inherited:yes.

For further information, refer to: http://www.w3.org/TR/CSS2/text.html#propdef-text-decoration

Overall, everything is functioning perfectly fine :)

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

I am interested in creating a similar layout using Bootstrap Studio

I've been attempting to align a text with borders and a button in one row, similar to the layout shown in this image, but I keep failing. I've experimented with different layouts such as two-column layout, one row, two-column layout, simple div, ...

When it comes to using jQuery, I find that it only functions properly when I manually input the code into the Google Chrome console. Otherwise

Below is the HTML snippet: <textarea cols="5" disabled id="textareRSAKeypair"> @Model["keypair"] </textarea> <a href="#" class="btn btn-primary" id="downloadKeypair">Download Key</a> Here is the jQuery code: <script src="ht ...

Setting a JavaScript variable to null

Using Jquery, I have a variable that is assigned a value on button click. After the code executes successfully, I need to reset the variable to null. $("#btnAdd").click(function () { var myDataVariable= {}; myDataVariable.dataOne="SomeDa ...

Tips on deleting a section of text inside a div

I have a DataTables implementation that is displaying an input inside a label element like this: <label> Search: <input type="search" class="" placeholder="" aria-controls="example"> </label> My goal is to remove the "Search:" t ...

Setting up Node JS with the essentials

Recently, I successfully installed Node JS on my EC2 instance (server) by following the detailed guide provided on this helpful website: After completing the installation process as per the instructions, I attempted to implement Node in my project. Howeve ...

"Unlocking the Power of CK Editor for Maximizing Value and Effectively Managing

I have a form with a field titled Description. I am using CKEditor to pass the value entered into this field and store it in my database. Can someone assist me with this? Below is the code snippet: <div id="descriptionMore" style="margin-bottom:20px; ...

Spin: twist beyond 360 degrees or less than 0 degrees

Attempting to rotate an arrow indicating wind direction using the transform: rotate() property. The data for rotation is retrieved from an API fetch, and conventional measurement of wind direction involves indicating where the wind is coming from. Therefo ...

Tips for pre-setting a select field using jQuery when the page loads

Recently, I enlisted the help of a developer to create some code in my WordPress footer.php file that would predefault a set of fields based on the user's profile. While the text fields default correctly, the select option for gender does not default ...

Seeking guidance on how to effectively implement jQuery AJAX autocomplete functionality

I am attempting to implement a jQuery AJAX autocomplete extender for the first time, but I am encountering some issues. I would appreciate it if someone could help me identify any errors and provide suggestions to make this feature work correctly. & ...

Dynamically update a form with steps using JQuery-steps and send all objects to the controller

In the context of a form, it is possible to dynamically add between 1 to n records before passing it to the controller with data. The following represents the ViewModel for the form: public class AddFieldDataViewModel { public int SampleID { get; se ...

What is the best way to save variables to a file in opencart?

I'm encountering an issue with posting variables in opencart. My goal is to retrieve two variables from text fields on the checkout/login page, labeled as name and address. I intend for the values inputted into these fields to be saved upon clicking t ...

What is the best way to align a form in the center of a page both horizontally and vertically

Currently, this is the HTML code I am working with: <body> <form id="form_login"> <p> <input type="text" id="username" placeholder="username" /> </p> ...

Navigational assistance on the keyboard - Improving Accessibility

My situation involves selecting an option from a dropdown menu on X-page, which triggers the opening of Modal-1 while disabling the background. If a selection is made within Modal-1, it leads to Modal-2. I am facing two issues/questions: Upon opening Moda ...

Is there a way for me to keep an image stationary on the page while allowing overlaying text to move?

Currently, I am exploring the process of coding a website that mimics the style of this particular webpage: . I am particularly interested in learning how to create a scrolling effect for text within a fixed area, while keeping the accompanying images st ...

Why is my client program not receiving a response from this socket.io server?

Currently, I am in the process of developing a trivia game where two users engage in answering questions with the winner being declared at the end. As part of this project, I have integrated socket.io to facilitate the exchange of answers. However, I have ...

Executing Javascript code from a specified web address

Let's say I have an image that needs to be shifted vertically, and I achieve it using the following code snippet: document.getElementById('ImgID1').style.verticalAlign = However, the value by which I need to shift the image is provided thr ...

Ways to ensure that an element is aligned within a parent div with a 100% bottom position

I am facing a small issue that I need help with. My problem is aligning an element to the top of a percent div with bottom: 100%, and I just can't seem to make it work within the parent div. Essentially, I want bottom: 0% to align with the bottom of ...

Create a dynamic dropbox using JavaScript/JQuery in an HTML page

I am currently working on implementing 3 different drop down boxes that are triggered by 4 different buttons. These drop down boxes should appear within the #apple div. When Button B1 is clicked, the drop down options include Apple, Mango, and Papaya. Whe ...

Error: Unable to locate requested resource

I have a scenario in Struts2 where I am utilizing an AJAX code snippet in the Script Section. var url="../scriptWay/myCallToBackEnd.ac?myToy="+myToyInfo; var respObj = ""; new Ajax.Request(url,{ ...

Open $_POST in a new tab that has been edited for your convenience

<form method="post" target="_blank" action="battle.php" onsubmit="window.open('battle.php','','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=0,left=30,top=0');" > < ...