Evaluation of jQuery-created CSS for placeholders

When I needed a placeholder for input, I began testing it on Chrome, Mozilla, and IE 10 (with IE8 still pending).

The placeholder attribute worked well in Chrome and Mozilla, but had strange behavior in IE 10. The text would disappear as soon as the input was focused, even before anything was typed.

I discovered that this was a bug in IE and later found an alternative at Placeholder using jQuery, which worked perfectly in IE 10, Mozilla, and Chrome. However, its compatibility with IE 8 remains uncertain.

My query is:

Will the jQuery-created placeholder outperform the built-in CSS attribute "placeholder"? If jQuery's performance is lacking, I am willing to stick with the CSS attribute despite the flawed behavior in IE. This decision is crucial as the page I am working on will experience heavy traffic. Additionally, I need to test jQuery in IE 8.

Solution Post Feedback: I have decided to opt for the jQuery-generated CSS due to several reasons:

  1. IE 8 does not support the placeholder attribute.
  2. IE 10 experiences issues with the behavior of placeholders.
  3. A simple jQuery plugin ensures compatibility across IE, Mozilla, and Chrome, with room for customization.
  4. Considering that my page will only feature up to 4 input fields, the minor impact on performance compared to CSS is acceptable given the low number of elements on the page.

Answer №1

Check out the CanIUse website and see that only IE9 and older versions require a placeholder attribute polyfill. You can easily activate the polyfill based on Modernizr's detection of native placeholder attribute support.

Regarding IE10, as mentioned in the comments, there will be a solution from the IE team coming soon.

To address your specific question without testing, it's generally considered safer to rely on native browser implementations of features rather than JavaScript versions that need to be processed and interpreted by the browser. While performance differences may not be significant, a well-designed polyfill can sometimes outperform a poorly implemented native solution. Poor performance usually arises when animations or event handlers are misused, running too frequently or taking too long to execute each time.

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

Display all pages in the DataTables plugin while utilizing responsive tables and additional features

I am struggling to combine the responsive and fixed header attributes of my current function with the "Show All" list feature, similar to what is demonstrated in this example: https://datatables.net/examples/advanced_init/length_menu.html I need assistanc ...

What is the best way to increase the size of an entire component within a

If I have a fixed DIV container size of 375px * 667px for a phone, how can this DIV and all elements inside (images, text, etc) automatically enlarge when viewed on a desktop browser? original fixed div auto enlarge ...

Changing the Direction of News Ticker Movement from Right to Left

I need to switch the news ticker movement direction from right to left to left to right because I will be using Arabic language, so it is crucial to change the movement direction. Despite trying for several days, I have been unable to find a solution. HTM ...

Displaying an additional section using hover effects in Bootstrap

I recently utilized Bootstrap to create pricing tables which can be viewed here: http://www.bootply.com/VyHsJBDoNc Is there a way for me to implement hover functionality on a span element (+ More Information!) that will display additional information as s ...

Creating Bootstrap Popover dynamically on a jQuery DataTable is a straightforward process that can enhance user experience

I am currently populating a table with data retrieved from an ajax call. The filling process is done through the use of append method as shown below: var table = //something //loop through ajax response objects table.append('<tr><td>&apo ...

Trigger a keypress event following the activation of a button

I've been trying to simulate the press of the backspace key on the keyboard after clicking a button, but all my attempts have been unsuccessful. Here is the code I'm using: function rtf(){ document.getElementById("u0u").focus(); $('#u0u ...

Having successfully configured and published Google Tag Manager, unfortunately, I am encountering difficulties in displaying the tag on the website

After setting up my GTM account and creating containers, tags, etc., I encountered an issue. Even after publishing my container and creating a version, when I checked my website, all the code was hidden within a div tag with display none and visibility hid ...

Is it possible and advisable to compress the css within an email?

Recently, I've integrated into my website for email campaigns. I'm curious to know if it's possible to minify the CSS code in emails to just one line, or if it's better to leave it as is? ...

The bxSlider reloadSlider() function is not defined once the page has finished loading

I am currently working on developing an interactive upload and refresh gallery using AJAX and jQuery. The application allows for the upload of multiple images through drag & drop. After uploading, I need to visualize how the new gallery will appear with t ...

LESS: Using variable values in mixin and variable names

I am looking to simplify the process of generating icons from svg-files while also creating a png-sprite fallback for IE8 support. I am using grunt.js and less. I was inspired by the implementation on 2gis.ru: (in Russian), where they used technologies s ...

Enhance the appearance of specific wordpress usernames by adding a touch of "flair" next to them

I'm looking to add a special "flair" next to specific users on my WordPress website, similar to how YouTube distinguishes verified users. I have the CSS for changing the color on hover, but I need help keeping it positioned correctly. Examples from Y ...

Misaligned Div Content

Check out my jsfiddle here The text inside the <div> is shifting upwards Could someone explain why this is occurring? And suggest a solution? I would truly appreciate any assistance. Thank you! ...

Adjusting the color of text according to its value

I am a beginner with PHP, MySQL, and jQuery. I am working on a service desk form and database where I can input and display data effectively. However, I am looking to implement a feature that changes the color of text based on the value in the MySQL databa ...

Encountered an Ajax issue while initializing a datatable on a table inside a modal dialog

I have a modal that contains a search box. When the search button is clicked, an ajax call is made to the controller to retrieve a table of results, which are then inserted into a div like this: $.ajax({ url: url, data: JSON.stringify(viewModel), ...

What is the best way to substitute </br> and <br/> with in a text?

Is there a way to replace </br> and <br/> with \n functionally? There seems to be varied responses to this query. Errors are often made when writing the break tag. The solutions for both types of breaks mentioned above are detailed below ...

I'm encountering issues with saving data via ajax because of datetime and foreign key constraints

I need assistance with storing vacation data for a specific employee based on the employee ID obtained from the URL. Currently, when I select an employee from a list, the code displays their associated vacations, and I would like to add a new entry. Can yo ...

JQuery novice just starting out

What is the issue with my JQuery script? <script type="text/javascript"> $(".header").click(function () { $header = $(this); //getting the next element $content = $header.next(); //open up the content needed - toggle the slide- if visible, slid ...

Popovers in Bootstrap 4 not functioning properly within Wordpress Understrap theme

Currently, I am working with the Understrap child theme on Wordpress and I am facing issues getting popovers, tooltips, and vertical pills to function correctly. You can see an example of the problem on this live page: Sample Page It seems like Popper.js ...

Utilizing jQuery to target elements by their class name within a specific component

I currently have 3 separate jQuery components on my webpage. id=#table1 id=#table2 id=#table3 Within each table, there is a div with the class "black". My task is to target the specific div with the class black inside table3 only. Although $(".black" ...

The Boostrap Datepicker fails to display

I'm having trouble integrating a Bootstrap Datepicker into my form. I got it working outside of the form, but when I try to include the code in my form, it doesn't seem to work. All necessary files are present and the code is identical. <!D ...