Javascript function not triggering onFocus event

Click here to view the fiddle. I am attempting to create a glowing effect on a textbox using onFocus in the input tag. The goal is to make the textbox glow when it is clicked and the border changes color. I have tried writing JavaScript code, but unfortunately, it does not seem to be working properly.

This is my JavaScript code:

function input() {
    var x = document.getElementById('input');
    x.style.box-shadow = '0 0 30px #96f226';
}

Answer №1

Modify the box-shadow property to boxShadow. Use this code snippet for switching focus:

function inputFocus(elem) {
    elem.style.boxShadow = '0 0 30px #96f226';
}
function inputBlur(elem) {
    elem.style.boxShadow = 'none';
}

<input type="text" onFocus="inputFocus(this)" onBlur="inputBlur(this)">

View jsfiddle example

CSS Style

#input:focus {
   box-shadow: 0 0 30px #96f226;
   -webkit-box-shadow: 0 0 30px #96f226;
   -moz-box-shadow: 0 0 30px #96f226;
}

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 are some ways to avoid an image looking faded when adding it to the scene background in Three.js?

I've been experimenting with loading images onto the scene background using the TextureLoader() class to prevent them from appearing greyed out. Following a tutorial on three.js https://www.youtube.com/watch?v=xJAfLdUgdc4&list=PLjcjAqAnHd1EIxV4FS ...

Using a $watch on a directive that has an isolated scope to monitor changes in a nested object property retrieved from

I have developed a custom directive with an isolated scope and element. I am utilizing the values passed into the directive to construct d3/dc charts. The data goes through crossfilter on the $scope so that the directive attributes can access it. Despite s ...

React app experiencing freezing due to custom asynchronous function utilisation

I am currently facing an issue with my personal project where the application freezes under certain circumstances. The initial load works fine, but when I make changes to the code causing React to re-render, the app just freezes. It seems to be related to ...

Sets a minimum width for a Bootstrap panel

I have a panel panel-default on my page to display some data. I want the panel's min-width to be 720px, and if the window is resized to less than 720px, I want a horizontal scrollbar to appear. However, the panel cannot shrink below 720px similar to u ...

Steps to integrating an interface with several anonymous functions in typescript

I'm currently working on implementing the interface outlined below in typescript interface A{ (message: string, callback: CustomCallBackFunction): void; (message: string, meta: any, callback: CustomCallBackFunction): void; (message: string, ...m ...

How can I use Node.js Express to send a response in a file format like JavaScript or another type?

Currently, I have a piece of code that successfully reads the 'example.js' file and sends it to the client as requested. app.get('/mods/example.js', function(req, res) { fs.readFile('./mods/example.js', {encod ...

Converting values to hexadecimal in PHP inspired by Javascript's .toString(16)

Is there a way to achieve the same result as JavaScript's .toString(16) in PHP? var n = 200000002713419; console.log(n.toString(16)); When executed, this code returns b5e6211de74b. Is there any equivalent function in PHP to achieve the same output? ...

Trigger an AJAX request by clicking on a specific div element

My goal is to trigger an AJAX call when a user clicks on a location marker in a Google map integration. The function info_window_content, available at this link: http://jsfiddle.net/6xw2y/, is responsible for creating the necessary div elements within the ...

What kind of registration does React Hook Form use?

When utilizing react-hook-form alongside Typescript, there is a component that passes along various props, including register. The confusion arises when defining the type of register within an interface: export interface MyProps { title: string; ... ...

Issues with Dependency Injection in Angular.js

I've been working on Dependency Injection and trying to make my code more modular in Angular.js. After researching some tutorials, I decided to try and rewrite it. Here's what I initially planned (although I may have misunderstood some concepts, ...

Can using $.ajax to submit a form be considered contradictory?

Currently, I am engaged in developing an MVC application that heavily relies on jQuery and HTML forms. However, I have started to notice a conflict between the two... For instance, I have had to prevent the default form submission to execute my AJAX call ...

What is the best way to retrieve this JSON data?

I'm new to JavaScript and struggling to access a specific value in a JSON string. I tried looping through the objects using $.each function, but it didn't work. When I attempted to access the 'type' value with alert(data.type), it retur ...

I am having an issue where my Bootstrap 4 col-sm-6 rows are not properly stacking on mobile devices

Currently facing issues with Bootstrap 4 as my columns are not stacking on top of each other in mobile view. I have two col-sm-6 within each row. Any guidance on how to resolve this would be greatly appreciated, thank you! Feel free to visit the website a ...

Intel XDK combines the power of Google API and JQuery to create

I want to incorporate the Google Url Shortener API into a cross-platform app that I am developing using Intel XDK. Interestingly, it appears that there is no Same-Origin Policy (SOP) enforced in the emulator. However, when I try to make a request, I receiv ...

Exploring iPhone Safari Web App: Discovering functions tailored for iPhone users

I am exploring the possibilities of accessing native iPhone features while developing a Web App using html/css/javascript and running it in Safari. I am curious to know if I can tap into smartphone-specific features, especially those unique to iPhone/iTou ...

What advantages does Protractor offer for non-angular applications?

I am in the process of setting up automated tests and am curious about the advantages of using Protractor to automate non-angular applications. Can anyone shed some light on the benefits compared to solely using webdriverJS? ...

Output a MySQL field value into a checkbox by utilizing an if statement

Hey there, I'm really close to getting this statement to work correctly but I just can't seem to figure it out. So I have an overtime field from MySQL and I am able to display it. However, I'm trying to make it either checked or not checked ...

The TypeScript compiler generates a blank JavaScript file within the WebStorm IDE

My introduction to TypeScript was an interesting experience. I decided to convert a simple JavaScript application, consisting of two files, into TypeScript. The first file, accounts.ts, contains the main code, while the second one, fiat.ts, is a support f ...

Unable to eliminate top margin in Bootstrap 3 affix feature

Struggling to locate the source of the margin-top when utilizing the affix plugin on my Navbar. You can view [my website here] for better understanding. Should I be implementing Javascript to solve this issue? My current skills in that area are not very ...

I'm experiencing an issue where the links in my dropdown button are not showing when I hover over it. What could

I have been attempting to include a dropdown button that reveals several links when the mouse hovers over it. Despite successfully implementing the CSS for this feature, I am encountering an issue where the links are not displayed beneath the button. Afte ...