I am working in django and have created a class which has a field closed
. When the user sets this value for a particular object, then I want to disable all buttons and links on the object_view
page.
I am using the following jquery
snippet, but it is not working. Can anybody help me find the mistake
<script type="text/javascript">
$("a").css('cursor','arrow').click(function(){
return false;
});
$("input").attr('disabled','disabled');
</script>
Update: Not working means that all the links and input buttons are still working, i.e. being directed to the correct page. I have included this code snippet in my <head>
section.
I am working in django and have created a class which has a field closed
. When the user sets this value for a particular object, then I want to disable all buttons and links on the object_view
page.
I am using the following jquery
snippet, but it is not working. Can anybody help me find the mistake
<script type="text/javascript">
$("a").css('cursor','arrow').click(function(){
return false;
});
$("input").attr('disabled','disabled');
</script>
Update: Not working means that all the links and input buttons are still working, i.e. being directed to the correct page. I have included this code snippet in my <head>
section.
- Define "not working". Does it do anything? Are there errors on your console? – James Montagne Commented Jan 13, 2012 at 20:20
- Works fine for me: jsfiddle/x9JCU – ComFreek Commented Jan 13, 2012 at 20:21
- make sure you have jquery included – Grigor Commented Jan 13, 2012 at 20:24
3 Answers
Reset to default 4Try:
<script type="text/javascript">
$(document).ready(function(){
$("a").css("cursor","arrow").click(false);
// for jquery older than 1.4.3, use the below line
// $("a").css("cursor","arrow").click(function(){
// return false;
// });
$(":input").prop("disabled",true);
// for jquery older than 1.6, use the below line
// $(":input").attr("disabled","disabled");
});
</script>
You need the $(document).ready(...)
so that the code doesn't run until the elements exist on the page.
I guess you could turn off all links (that is anchor tags) with something like this:
$("a").click(function (e) {
e.preventDefault();
});
This should work for buttons and other inputs
$(":input").attr('disabled','disabled');
You need to wrap the whole thing in:
$(function() {
});
OR
$(document).ready(function () {
});
To limit the input to buttons:
$('input[type="button"]').attr("disabled","disabled");
Otherwise you disable all input elements.