Skip to content
  • home
  • portfolio
  • web design journal
  • blog
    • adventure
    • san diego
    • urbanity & architecture
    • projects
    • website design
Blog Web Dev Simple Div Popup

Simple Div Popup

By Forrest Smith - Drempd.com

I wanted a simple popup. Click on a link, it opens a div. When you mouse off the div, or the link, it goes away. Pretty easy:

The jQuery

$(document).ready(function(){

    var timer;

    $('.dropdiv-link').click(function(e){
        e.preventDefault();
        var target = '#'+$(this).attr('data-target');
        
        if ($(target).is(":visible")){
            $(target).hide();
        }
        else{
            $(target).show();
        }
    });
	
    $('.dropdiv-dropwindow').mouseover(function(e){
        clearTimeout(timer);
        $(this).show();
    });

    $('.dropdiv-link').mouseout(function(e){
        timer = setTimeout(function(){$('.dropdiv-dropwindow').hide()},500);
    });

    $('.dropdiv-dropwindow').mouseout(function(e){
         $('.dropdiv-dropwindow').hide();
    });
});

The HTML

Just change the data-target to match the id of the div that you want to show or hide.

<a href="#" class="dropdiv-link" data-target="drop1">Test Link</a>
<div id="drop1" class="dropdiv-dropwindow">Test Div</div>

The CSS

.dropdiv-dropwindow{
    display: none;
    position: absolute;
}
Posted on January 5, 2014August 26, 2022 in Web Dev
  • Adventure

    • adventure
    • gravelgrinding
    • hiking
    • running
  • The Built Environment

    • architecture
    • urbanity
  • Locations

    • san diego
    • portland
  • Freelance Life

    • freelancing
    • productivity
  • Web Dev

    • css
    • entrepreneurship
    • git
    • handlebars
    • html
    • inkscape
    • photoshop
    • php
    • sass
    • web design
    • web development
    • saphire

drempd | san diego, ca


home contact

adventures san diego urbanity and architecture projects stream website design

portfolio resume san diego web design freelance web designer

custom web design responsive web design website maintenance