Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Focus to an image of a HTML page

I have 4 images that when I click them they show information under the images and when I click the last ones the images go under the page and whens the new page loads with that information I have to go down with scroller to see the image and information of the last image.

I want to put focus to the last image when the new page loading.

I do this but it's not working:

<script>
function setFocusToTextBox(){
    document.getElementById("abc").focus();
}
</script>

<img src="images/Practidose.fw.png" alt="" width="770" height="150" id="abc" onclick="setFocusToTextBox()"/>

Picture of the 4 images and when I click the last one I want to focus that image when the new page loads:

like image 205
rubcpires Avatar asked Apr 17 '14 11:04

rubcpires


1 Answers

.focus() can normally only be applied to links or form inputs.

However, you can use it on arbitrary elements by giving the element a tabindex attribute.

This is usually a good idea for accessibility reasons anyway if you want to make use of onClick handlers, as this will help keyboard navigation and other accessibility tools understand that your element is supposed to be clickable.

like image 140
Niet the Dark Absol Avatar answered Sep 28 '22 06:09

Niet the Dark Absol