Jump to content

Trying To Get Button Inside Anchor Tag to Valididate in HTML5


jimmyoneshot

Recommended Posts

At the moment I have the following markup:-

 

<script type="text/javascript">
    function save(x) {
       id=x.form.getAttribute("data-id");
       //Do stuff here to save the photo based on the above id
    }
</script>

<style>

.photo button{
        display:none;
}

.photo:hover button{
        display:block;
}

.photo:hover img{
width:200px;
height:200px;
position:absolute;
top:-8px;
left:-8px;
}

</style>

<form data-id="1">
   <a class="photo">
      <img/>
      <button onclick="save(this);return false;"></button>
   </a>
</form>

 

Basically this is one item within an image gallery. And I have my css setup so that when a user hovers over the anchor tag the image enlarges and the button's display is set to block so that it can be clicked upon which the photo will be saved by the user.

 

As you can see I need to use the button as the clickable element because in my save function I use x.form.getAttribute("data-id") and the .form is only applicable to form elements. Problem is this won't validate in HTML5.

 

Are there any alternatives which will validate?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.