I have two rectangles with some text inside. I would like to display a different alert when I click on each one, but code below doesn't work (alert is not displayed). Any ideas? Thanks
<div id="panel0" style="width: 100%">
<div class="titleBox" id="rect0" onclick="alert('yeah1');"
style="height: 85px; width: 85px;">Hello</div>
<div class="titleBox" id="rect1" onclick="alert('yeah2');"
style="height: 85px; width: 85px;">Hello</div>
</div>
I have two rectangles with some text inside. I would like to display a different alert when I click on each one, but code below doesn't work (alert is not displayed). Any ideas? Thanks
<div id="panel0" style="width: 100%">
<div class="titleBox" id="rect0" onclick="alert('yeah1');"
style="height: 85px; width: 85px;">Hello</div>
<div class="titleBox" id="rect1" onclick="alert('yeah2');"
style="height: 85px; width: 85px;">Hello</div>
</div>
Share
Improve this question
edited Mar 3, 2017 at 6:45
KishanCS
1,3772 gold badges19 silver badges41 bronze badges
asked May 18, 2012 at 8:31
user411103user411103
12
- 4 your code works: jsfiddle/Cyx2n – Andreas Wong Commented May 18, 2012 at 8:32
- @user411103 Your code is working for me too... – Exception Commented May 18, 2012 at 8:33
- There's no problem with this code – Narayan Singh Commented May 18, 2012 at 8:33
- 2 is JS enabled on your machine/browser? – Massimiliano Peluso Commented May 18, 2012 at 8:33
- 1 @DavidMårtensson Why?! ...user411103: Yes, for sure. – lorenzo-s Commented May 18, 2012 at 9:56
1 Answer
Reset to default 3Try this
<div id="rect0" onclick="alert('yeah1');" style="height: 85px; width: 85px; background-color: #ff0000;">
Hello
</div>