about 9 months ago - 15 comments
jQuery is by far my favorite JavaScript framework in terms of simplicity and just pure DOM power. I picked up a little trick at a conference quite a few months back and improved upon it and thought it could benefit anyone that believes in the mantra of progressive enhancement. Here’s the line of More >
about 1 year ago - 9 comments
The tabindex is absolutely necessary for controlling the tab order through a really long form, from a usability and accessibility standpoint. This is probably not the preferred way to do this, you should be setting the tabindex attribute on all of your input elements in your html. Now if you work with lazy More >
about 1 year ago - 10 comments
Another great “little” solution with jQuery. Needed a simple way to protect all the forms on our site from being double submitted. There was an attempted solution in place on our app, that added an onsubmit to every form with a function above it called ignoreDoubleSubmit that tried to trap the event of More >
about 1 year ago - 9 comments
I basically needed the update button to be the default action on clicking enter in the form, but there were multiple submit buttons in my form and they weren’t in the order I needed due to UI design. This was a quick and dirty solution to select an html submit button and make it More >
about 1 year ago - 13 comments
DHTML dropdown menu’s have been greatly improved in terms of accessibility, standards compliance, and weight using the Suckerfish technique of building pure CSS-based menus and then attaching a small javascript that allows Internet Explorer 6 to mimic the CSS hover method. Once the die-hards hanging onto IE6 let go, we won’t have to worry More >
about 1 year ago
You could also use :
$(“:input”).each(function () {
this.focus(); });
This way you don’t need to set the class=”focus” .It uses the selectors api.
about 1 year ago
I’m not sure this accomplishes the same thing, how do you control which input box gains focus then? The idea behind setting a class of focus is, say you have a search field that’s always present in the header of the page that you want to have focus as long as nothing else has focus, but on certain pages like login, for example, you want the username field to have focus instead, in my example both would have a class of focus, but the last field with the focus class specified in the document would actually end up with the focus.
about 1 year ago
Im missing something here… only one element of a page can have the focus, so why are you using “each”?
Its easier something like this:
$(“#fieldId”).focus(); or $(“input.focus”).focus();
or maybe $(“:input:first”).focus();
Bye
about 1 year ago
You’re right there’s probably a better and more efficient way to do this rather than use each, it might even be a little lazy. The goal is to have the last field with focus specified receive focus. The each method does a couple of things for me: if there’s more than one field specified with focus, the method will loop through those elements and the last one will end up with focus; if there are no items with focus there will be no jQuery objects returned and I won’t end up with a javascript error because I asked for focus on something that didn’t exist. Note your syntax above is not correct as focus in this context is a DOM method, not a jQuery method.
about 1 year ago
I dont think so, $(…).focus() is another jQuery method, to call the DOM method you need this $(…).get(0).focus().
jQuery is smart enought to dont execute focus() if there is no matched elements, just like each(). Try it for yourself
“Triggers the focus event of each matched element”: http://docs.jquery.com/Events/focus
Thanks for reply
about 1 year ago
I stand corrected, I misinterpreted the doc, I’ll update the post. Thanks for the feedback.
about 1 year ago
using a class selector without a tagname is far far far slower. always use “input.focus” instead of “.focus” when possible.
about 1 year ago
Paul, thanks for the advice, I’ve updated the post again to reflect it. I’ve truly been schooled on this one.
about 7 months ago
Thanks, I needed this for one of the sites I’m working on…
about 1 month ago
There is no need to complicate things. You can do everything using selectors, following code will set focus on first visible input.
$("input:text:visible:first").focus();about 1 month ago
Actually there was a need to complicate it a little in order to have a level of control, with shared templates there’s a need for a hierarchy of focus, this is why I chose to give a class to the objects in the page that typically have focus and then apply focus to the last element with that class based on the document order.
about 6 days ago
Hi there. Guys, I have been using JQuery for the last 8 months and the more I use it the more I like it. The question I have is: Is there a bible for JQuery written down or Online which I can consult and study to become a Guru in the subject? can you direct it to me?
I really appreciate it.
about 5 days ago
jQuery has great documentation for their API at http://docs.jquery.com/Main_Page, of course there are tutorials and examples throughout the Internet. When I first started out I skimmed a book called Learning jQuery by Jonathan Chaffer and Karl Swedberg, once you get a lot of the concepts down you’ll find that you’ll use the API documentation 90% of the time.
about 5 days ago
Thank you a lot. I will go ahead and purchase the book I mean, I have been going off and on to the API documentation and I have managed to add few jquery features to some sites I have worked on however I feel like I gotta work more on the fundamentals and concepts. Every time I have to use JQuery I end up fishing some pieces of code written by somebody else (which is not bad per sea) but it doesn’t come easy.
Cheers.