


The problem of jQuery obtaining the color value in CSS style, different solutions for different browser formats_jquery
When using jQuery to obtain the value of background-color in the style, I found that the obtained color value is displayed in HEX format [#ffff00] in versions below IE10, while in IE10, Chrome, and Firefox it is in GRB format. Display [rgb(255,0,0)]. Since the color value needs to be judged and processed, it is necessary to obtain a unified color format, preferably in HEX format, to facilitate processing. After searching, I got a piece of code from a foreign website:
$.fn.getHexBackgroundColor = function() {
var rgb = $(this).css('background-color');
rgb = rgb.match(/^rgb((d ),s *(d ),s*(d ))$/);
function hex(x) {return ("0" parseInt(x).toString(16)).slice(-2);}
return rgb= "#" hex(rgb[1]) hex(rgb[2]) hex(rgb[3]);
}
The above definition is a jQuery function, we You can get the RGB value of the background-color with tag id="bg" through $("#bg").getHexBackgroundColor();.
Let’s make a small modification, that is, add a judgment. If the HEX value is displayed (below IE10), just get the value directly. If it is a non-IE browser, convert the value into RGB format:
$.fn.getBackgroundColor = function() {
var rgb = $(this ).css('background-color');
if(rgb >= 0) return rgb;//If it is a hex value, return directly
else{
rgb = rgb.match(/ ^rgb((d ),s*(d ),s*(d ))$/);
function hex(x) {return ("0" parseInt(x).toString(16)).slice( -2);}
rgb= "#" hex(rgb[1]) hex(rgb[2]) hex(rgb[3]);
}
return rgb;
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to implement cross-application jump for Word plug-in login authorization? When using certain Word plugins, we often encounter this scenario: click on the login in the plugin...

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

Discussion on the task status after the local computer of Jiutian Computing Power Platform is closed. Many users will encounter a question when using Jiutian Computing Power Platform for artificial intelligence training...

Problems and solutions encountered when using the requests library to crawl web page data. When using the requests library to obtain web page data, you sometimes encounter the...

This article introduces various methods to troubleshoot and fix memory leaks in Flutter applications on Debian systems. 1. Use FlutterDevTools to detect memory leaks to install DevTools: Run flutterpubglobalactivatedevtools in the terminal to install FlutterDevTools. Run the application (Profile mode): Use flutterrun--profile to run your Flutter application and enter performance analysis mode. Start DevTools: Open http://localhost:9 in the browser

"DebianStrings" is not a standard term, and its specific meaning is still unclear. This article cannot directly comment on its browser compatibility. However, if "DebianStrings" refers to a web application running on a Debian system, its browser compatibility depends on the technical architecture of the application itself. Most modern web applications are committed to cross-browser compatibility. This relies on following web standards and using well-compatible front-end technologies (such as HTML, CSS, JavaScript) and back-end technologies (such as PHP, Python, Node.js, etc.). To ensure that the application is compatible with multiple browsers, developers often need to conduct cross-browser testing and use responsiveness

JupyterNotebookMarkdown rendering problem troubleshooting is using Jupyter...
