How to set background color of HTML element using css properties in JS

How to set background color of HTML element using css properties in JavaScript How can I set the background color of an HTML element using css in JavaScript? 17 Answers In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So background-color becomes backgroundColor . function setColor(element, color) { element.style.backgroundColor = color; } // where el is the concerned element var el = document.getElementById('elementId'); setColor(el, 'green'); I'd like to add the color obviously needs to be in quotes element.style.backgroundColor = "color"; for example - element.style.backgroundColor = "orange"; excellent answer In Selenium tests: ((IJavaScriptExecutor)WebDriver).ExecuteScript("arguments[0].style.background = 'yellow';", webElement); @Catto In this case, color is an argument to the function, hence it should not be in quotes. However, you are right that normally, i

How can I make the browser see CSS and Javascript changes?

How can I make the browser see CSS and Javascript changes? CSS and Javascript files don't change very often, so I want them to be cached by the web browser. But I also want the web browser to see changes made to these files without requiring the user to clear their browser cache. Also want a solution that works well with a version control system such as Subversion. Some solutions I have seen involve adding a version number to the end of the file in the form of a query string. Could use the SVN revision number to automate this for you: ASP . NET Display SVN Revision Number Can you specify how you include the Revision variable of another file? That is in the HTML file I can include the Revision number in the URL to the CSS or Javascript file. In the Subversion book it says about Revision: "This keyword describes the last known revision in which this file changed in the repository". Firefox also allows pressing CTRL+R to reload everything on a particular page. To cl

How can I detect if a browser is blocking a popup? - JavaScript

How can I detect if a browser is blocking a popup? Occasionally, I've come across a webpage that tries to pop open a new window (for user input, or something important), but the popup blocker prevents this from happening. What methods can the calling window use to make sure the new window launched properly? 9 Answers If you use JavaScript to open the popup, you can use something like this: var newWin = window.open(url); if(!newWin || newWin.closed || typeof newWin.closed=='undefined') { //POPUP BLOCKED } Here's an answer for chrome: detect-blocked-popup-in-chrome @ ajwaka could you kindly clarify if this answer fails for chrome, or is there a reason the other answer is better for chrome? thanks! @ ajwaka at least today this code seems to work on chrome, hence the question. @ Crashalot - You're asking me about something I answered this 6 years ago - I sadly no longer recall the situation and browsers have come a long ways in 6 years. I tried a nu

How do I delimit a databound Javascript string parameter in ASP_NET

Triple Quotes? How do I delimit a databound Javascript string parameter in ASP . NET? How do I delimit a Javascript data-bound string parameter in an anchor OnClick event? I have an anchor tag in an ASP . NET Repeater control. The OnClick event of the anchor contains a call to a Javascript function. The Javascript function takes a string for its input parameter. The string parameter is populated with a data-bound value from the Repeater. I need the "double quotes" for the Container.DataItem . I need the 'single quotes' for the OnClick . And I still need one more delimiter (triple quotes?) for the input string parameter of the Javascript function call. Since I can't use 'single quotes' again, how do I ensure the Javascript function knows the input parameter is a string and not an integer? Without the extra quotes around the input string parameter, the Javascript function thinks I'm passing in an integer. The anchor: <a id="aSho

ASP_Net Custom Client-Side Validation

ASP . NET Custom Client-Side Validation I have a custom validation function in JavaScript in a user control on a .Net 2.0 web site which checks to see that the fee paid is not in excess of the fee amount due. I've placed the validator code in the ascx file, and I have also tried using Page.ClientScript.RegisterClientScriptBlock() and in both cases the validation fires, but cannot find the JavaScript function. The output in Firefox's error console is "feeAmountCheck is not defined" . Here is the function (this was taken directly from firefox->view source) <script type="text/javascript"> function feeAmountCheck(source, arguments) { var amountDue = document.getElementById('ctl00_footerContentHolder_Fees1_FeeDue'); var amountPaid = document.getElementById('ctl00_footerContentHolder_Fees1_FeePaid'); if (amountDue.value > 0 && amountDue >= amountPaid) { arguments.Is

Multiply | JavaScript (solved) | codewars

Multiply in JavaScript (Solved) This code does not execute properly. Try to figure out why. Solution function multiply(a, b) { return a * b; } Multiplication The multiplication of whole numbers may be thought of as repeated addition; that is, the multiplication of two numbers is equivalent to adding as many copies of one of them, the multiplicand, as the quantity of the other one, the multiplier. Both numbers can be referred to as factors. Example: 3 * 4 = 4 + 4 + 4 = 12 return The return statement ends function execution and specifies a value to be returned to the function caller. Syntax return [expression]; Parameters expression The expression whose value is to be returned. If omitted, undefined is returned instead. Description When a return statement is used in a function body, the execution of the function is stopped. If specified, a given value is returned to the function caller. How to detect which one of the defined font was used in a web page?

How to detect which one of the defined font was used in a web page?

How to detect which one of the defined font was used in a web page? Suppose I have the following CSS rule in my page: body { font-family: Calibri, Trebuchet MS, Helvetica, sans-serif; } How could I detect which one of the defined fonts were used in the user's browser? For people wondering why I want to do this is because the font I'm detecting contains glyphs that are not available in other fonts. If the user does not have the font, then I want it to display a link asking the user to download that font (so they can use my web application with the correct font). Currently, I am displaying the download font link for all users. I want to only display this for people who do not have the correct font installed. One thing to keep in mind is that some browsers will replace certain missing fonts with similar fonts, which is impossible to detect using the JavaScript/CSS trick. For example, Windows browsers will substitute Arial for Helvetica if it's not installed. The tr