Forum Moderators: not2easy
.myDiv {
text-align: center;
overflow-y: scroll;
display: none;
position: fixed;
top: 50px;
left: 10px;
height: 300px;
width: 450px;
}
The images are broken up into categories, like group 1, 2, and 3, and the div becomes visible when someone clicks a link to unhide it.
I put an anchor at the top of each category, like <a id="group1">. Then at the top of the div I put a link that uses javascript to give focus to the anchor, like this:
<script>
function giveFocus ( id ) {
document.getElementById(id).focus();
}
</script>
<a href="javascript:giveFocus('group1');">Go to group 1</a>
<a href="javascript:giveFocus('group2');">Go to group 2</a>
<a href="javascript:giveFocus('group3');">Go to group 3</a>
In firefox the result is what I wanted -- the div scrolls to the anchor. On IE7 nothing happens though.
Anyone know of another way to give focus to an element in IE7?
PS. doctype is html 4 strict
we might need the a (non)working sample, it seems to me this might be better answered in JS, BUT if you are using a CSS hover or focus to activate a div change on mouseover that should be possible in CSS too but we would need the HTML structure as the pseudo properties can only effect a child element, as opposed to a "get element by id or class" function
if it turns out you want the latter then we can move your post to the appropriate forum
...I put a link that uses javascript to give focus to the anchor... In firefox the result is what I wanted -- the div scrolls to the anchor. On IE7 nothing happens though.
I did not think that the browser would necessarily scroll the page to an element by simply setting focus to it? (Although this appears to be happening in FF?) In order to scroll the page to the required element (which would not necessarily change focus to it) then I would have thought you would need to find the x,y position of that element and then use
window.scrollTo(x,y)to actually scroll the page?
...Anyone know of another way to give focus to an element in IE7?
If the element supports focus then the .focus() method is the only way to change focus in JS (IMHO). However, if you want to .scrollTo() that element...
---<edit>---
Hhmmm, I'd forgotten which forum I was in... yes, this does sound more like a JS query.