Reputation: 341
I have a <div>
with an ID - button2div. It is over another <div>
which has its background changed using JS.
<div id="button2div" onclick="location.href='#';" style="cursor:pointer;"></div>
I can to add a URL to button2div
using JS as a nested function.
addEventHandler(divarea1, 'mouseover', function () {
divbanner.style.backgroundImage ='url(URL To banner)';
buttondiv.style.backgroundImage ='url(URL To Button Background)';
$("button1div").click(function(){
window.location = 'http://google.com';
});
});
This does not work.
Note: the addEventHandle
r is from JQuery
.
How do I make this work? Thanks.
Upvotes: 0
Views: 317
Reputation: 684
Try this example with nested spans http://jsfiddle.net/dG26F/
$('span').click(function(){
alert($(this).attr('data-content'));
return false;
});
<span data-content="Hot Dog">
Hot
<span data-content="Dog">Dog</span>
</span>
span{
padding: 10px;
margin:5px;
background-color:#c67605;
display:inline-block;
}
span span{
background-color:#3a87ad;
}
Upvotes: 0
Reputation: 13956
missing # but you should not bind event in another event like that
addEventHandler(divarea1, 'mouseover', function () {
divbanner.style.backgroundImage ='url(URL To banner)';
buttondiv.style.backgroundImage ='url(URL To Button Background)';
});
$("#button1div").click(function(){
window.location = 'http://google.com';
});
Upvotes: 0
Reputation: 3575
Your missing a # (I presume), try this:
$("#button1div").click(function(){
window.location = 'http://google.com';
});
The # is a selector which represents your searching for an element which has the id given in the selector.
I.a. #mydiv searches for an element with the id 'mydiv'
Upvotes: 2