setting focus end of line

Hi Experts,

I have the following code for setting focus to the first input element.
			$(document).ready(function() {
    			var first_input = $('input[type=text]:visible:enabled:first, textarea:visible:enabled:first')[0];
    			if(first_input != undefined){ 

Open in new window

I put that in inside of head tag, so it can handle many different forms.
Now, I am trying to set focus end of line if there is already user input. Since there is no id for  most text fields and text areas, how do I handle that?
Isn't .get() function doesn't work either.

thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Add these lines after your focus line:
first_input.selectionStart = first_input.selectionEnd = first_input.value.length;

Open in new window

Works for inputs and textareas. Check this

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dkim18Author Commented:
It works. Thanks!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.