Reputation: 2198
Is there any function for hiding 'DIV's or other html elements on right click, some tutorial, script, simple code javascript or jquery. Example: when is click on link or
tag or 'li' or 'Ul' or 'a' with right click to hide this element... How to do that?
UPDATE: Yes, all your solutions is OK but please view this code and why doesn' work:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script>
$(document).on("mousedown", "div, img, span, a", function () {
if (event.which === 3)
$(this).hide();
});
</script>
<?php
$url = 'http://www.kupime.com/';
$data = file_get_contents($url);
$data = '<head><base href='.$url.' target="_blank" /></head>'.$data;
echo $data;
?>
And when I click nothing happend. WHY?
Upvotes: 2
Views: 442
Reputation: 83376
You can use event.which
in your mousedown handler to surmise whether the user clicked with the left, or right mouse button.
$(document).on("mousedown", "div", function() {
if (event.which === 3)
$(this).hide();
});
See this answer for more info on event.which
EDIT
Naturally, if you want to hide elements other than just div, you can comma-delimit them in on's selector
$(document).on("mousedown", "div, img, span, a", function () {
if (event.which === 3)
$(this).hide();
});
Or if you want to hide anything that's right clicked
$(document).on("mousedown", "*", function () {
if (event.which === 3)
$(this).hide();
});
Upvotes: 1
Reputation: 1397
I found the answer right here. That will show you how to know if you clicked it with the right mouse button.
It will turn out to be like this:
$("body").children().click(function(e) {
if(e.which === 3) { $(this).hide(); }
});
Upvotes: -1
Reputation: 100205
$("#yourDivId").click(function(e) { if(e.which === 3) { $(this).hide(); } });
Upvotes: 1