This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to distinguish between left and right mouse click with jQuery?
On right click I want to go to a different page..using jquery, how to do that? any idea?
thanks-
Something like this:
HTML
<a id="test" href=#">Click me</a>
JQuery
$(document).ready(function() {
$("#test").mousedown(function(e) {
switch (e.which) {
case 1:
alert("Left click... boring!");
break;
case 3:
alert("Right-click... off to new page...");
window.top.location = "http://www.google.com/";
break;
}
})
});
JSFiddle here
Related
This question already has answers here:
How to select an element inside "this" in jQuery?
(2 answers)
Closed 6 years ago.
<script type="text/javascript">
jQuery(".post-entry").click(function() {
window.location = jQuery(this).find("a").attr("href");
return false;
});
</script>
Is it possible to modify this script to find a href link that has a specific class? The reason is that some of these divs have multiple links within.
Absolutely.
$('.post-entry').click(function() {
window.location = $(this).find('a.example-class').attr('href')
return false;
})
If you want a hand cursor, you'll need a bit of CSS too:
.post-entry {
cursor: pointer;
}
This question already has answers here:
Prevent form submission on Enter key press
(20 answers)
Closed 9 years ago.
I am trying to scroll down the page using javascript.
I have this code which works fine if if i use javascript:pageScroll() in a link or button:
<SCRIPT LANGUAGE="Javascript">
function pageScroll() {
window.scrollBy(0,50); // horizontal and vertical scroll increments
scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
}
</SCRIPT>
but i need to find out how i can call the pageScroll() function if the user presses enter on their keyboard?
any help would be greatly appreciated.
$(document).keypress(function(e) {
if(e.which == 13) {
//do stuff
}
});
Use jQuery, you might be interested in .keypress(). Here: http://api.jquery.com/keypress/
Also you could have easily avoided this question by doing a simple Google search.
This question already has answers here:
jQuery : how to determine that a div is scrolled down
(7 answers)
Closed 9 years ago.
I want to call ajax function while scrolling inner scroll and append the results at the bottom of the existing results.
For refrence I've attached an image here.
How can I achive this?
You can use something like this without jQuery also
window.onload = function(){
if(window.addEventListener){
document.addEventListener('DOMMouseScroll', moveObject, false);
}
var myDiv = document.getElementById("myDiv");
myDiv.onmousewheel = ajaxFunction();
}
This question already has answers here:
Detect all Firefox versions in JS
(8 answers)
Closed 3 years ago.
I'm pretty new to Javascript. What I've learned is from just playing around with code.
I'm having trouble getting this to load. Bascially I need a certain div to only show in Firefox. Here is what I have.
<div id="parent" class="control-group"></div>
<script type="text/javascript">
$(document).ready(function() {
switch ( BrowserDetect.browser )
{
case 'Firefox':
$("button[name='btn']").click(function() {
$("#parent").html("<div></div>");
});
});
break;
}
</script>
You probably shouldn't be doing it like this, but if you are absolutely sure you only want to target Firefox:
var browser = navigator.userAgent.toLowerCase();
if (browser.indexOf('firefox') > -1) {
alert('Firefox');
}
fiddle
This question already has answers here:
How do I disable a href link in JavaScript?
(20 answers)
How do you make an anchor link non-clickable or disabled?
(19 answers)
Closed 6 years ago.
I have to disable anchor link depending on a condition if some data comes to that field it should work as a hyperlink and if that data does not come then the link should not be there?
Any ideas on this are welcome.
Case 1:
To disable:
document.getElementById(id).style.pointerEvents="none";
document.getElementById(id).style.cursor="default";
To enable:
document.getElementById(id).style.pointerEvents="auto";
document.getElementById(id).style.cursor="pointer";
Case 2:
If you want the link to be gone (not just disable it):
document.getElementById(id).style.display="none";
to get it back:
document.getElementById(id).style.display="block"; //change block to what you want.
Case 3:
If you want to hide it preserving the space for it:
document.getElementById(id).style.visibility="hidden";
To get it back:
document.getElementById(id).style.visibility="visible";
I couldn't make sense of your question body, so I'll answer your question's title...
How to disable anchor using javascript ?
JavaScript
if (condition) {
document.getElementsByTagName('a')[0].removeAttribute('href');
}
jQuery
...because everyone uses it, right?
if (condition) {
$('a').first().removeAttr('href');
}
with jQuery
if(!data){
$('#linkID').click(function(e) {
e.preventDefault();
});
}
with Prototype
if(!data){
$('linkID').observe('click', function(event) { event.stop() });
}
my link
function check(){
var data =document.getElementById("yourdatafield").value;
if(data)
window.location="your_link_location";
}
With jQuery:
To disable:
$('#anchor_tag').attr("disabled", true);
To enable:
$('#anchor_tag').attr("disabled", false);