jgravois jgravois - 7 months ago 32
jQuery Question

jQuery Loop through all with Placeholder and set focus

I am having an issue with the Material Design label animation collapsing on inputs with a dynamic value or placeholder. I want to loop through all input with a placeholder attribute on the page on page load and set the focus on that field to trigger that animation. After the loop I want to put focus on the first input.

I tried to add a class of "labeled" to all inputs with a placeholeder and a label and put the following in Document Ready, but it didn't work.



Try this:

jQuery(document).ready(function($) {
    $('input[placeholder]').each(function(index, el) {

you need to run an each because then you can add a trigger a focus event each time.