I want to disable this button on document ready but I'm new to it so please help:
Here is my code:
$(document).ready function {
setTimeout("check_user()", 250);
}
please help
If button's id is button1, this should work.
$('#button1').attr('disabled', 'disabled');
The correct way to disable a button in current versions of jQuery is:
$('#btnid').prop('disabled', true);
.attr() is the old way. See the jQuery 1.6.1 release notes for more information.
$(document).ready(function(){
$('#btnId').attr('disabled', 'disabled');
});
$(function(){
$('#button').attr('disabled', 'disabled');
});
$(document).ready(function(){
$('#buttonclass').attr('disabled', true);
});
Related
I wanna do openable menu on jquery. I use click methods and It's work but I can't close it. How can I close? Thank you :)
$("div#kkayit").on("click", function(){
$(this).css("background-color", "pink");
});
$("div#kkayit").on("click", function(){
$("div#kkayit").off("click");
});
You can use the function toggle in jquery:
http://api.jquery.com/toggle/
$(document).ready(function(){
$("button").click(function(){
$("p").toggle();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p> HERE Will toggle</p>
<button>Toggle between hide() and show()</button>
You have registered the same event for same selector two times. So I would recommend to use only below code for mentioned selector's click event.
$("div#kkayit").one("click", function(){
$(this).css("background-color", "pink");
});
http://api.jquery.com/one/
Please try below:
$("div#kkayit").on("click", function(event){
$(this).css("background-color", "pink");
event.preventdefault();
});
Please let me know if I answered your question or not.
Thanks.
Vinay
I was able to disable it like this
$('#div1').click(function(){
$(document).bind('touchmove', false);
});
But I want to enable it again when I click on another div, I tried:
$('#div2').click(function(){
$(document).bind('touchmove', true);
});
Am I doing something wrong?
I've never used this before.
$('#div2').click(function(){
$(document).unbind('touchmove');
});
I can't figure out why my button won't re-enable when another button is clicked. Any help will be most appreciated
My code is as follows:
$(document).ready(function() {
$('#btnAdd').click(function() {
// enable the "remove" button
$('#btnDele').attr('disabled','');
}
});
demo here: http://jsfiddle.net/ATzBA/2/
$('#btnDele').attr('disabled',false);
should do the trick.
You could also try $("#btnDele").removeAttr('disabled');
The prop function is the correct way to do this in JQuery.
$('#btnDele').prop('disabled', false); //enabled
$('#btnDele').prop('disabled', true); //disabled
$('#btnDele').prop('disabled'); //returns true if disabled, false if enabled.
See documentation here.
The "disabled" attr has to be removed completely, not just set to null/an empty string. You need to use jQuery's removeAttr():
$(function(){
$('#btnAdd').click(function(e){
$(this).removeAttr('disabled');
});
});
Somebody talks about it/browser compatibility issues here: Toggle input disabled attribute using jQuery
Instead of using the .attr function I'd use Jquery UI and use $('#btnDele').button("enable");
http://docs.jquery.com/UI/Button#methods
$(document).ready(function() {
$('#btnAdd').click(function() {
// to enable the "remove" button
// set 'disabled to false'
$('#btnDele').attr('disabled','false');
});
});
This is pretty standard stuff here, and I cannot understand why it isn't working.
When the enable function is called, I receive my alert but the select fields are still disabled. Any thoughts?
$(window.document).ready(function() {
$('#selectmenu1').attr('disabled','true');
$('#selectmenu2').attr('disabled','true');
$('#selectmenu3').attr('disabled','true');
});
function enableCoreChange(){
alert('called');
$('#selectmenu1').attr('disabled','false');
$('#selectmenu2').attr('disabled','false');
$('#selectmenu3').attr('disabled','false');
}
The click event:
Click here to enable
It's driving me crazy!
Pass a boolean, not a string, as the second parameter of .attr().
$(function() { // use document ready shorthand
// combine the selectors to stay DRY
$('#selectmenu1, #selectmenu2, #selectmenu3').attr('disabled', true);
});
function enableCoreChange() {
$('#selectmenu1, #selectmenu2, #selectmenu3').attr('disabled', false);
// alternately:
$('#selectmenu1, #selectmenu2, #selectmenu3').removeAttr('disabled');
}
Note the other general style improvements as well.
HTML:
Click here to enable
jQuery:
function enableCoreChange(){
$('#selectmenu1, #selectmenu2, #selectmenu3').prop('disabled', false);
}
$(document).ready(function(){
$('#selectmenu1, #selectmenu2, #selectmenu3').prop('disabled', true);
$('#enable').on('click',function(e){
e.preventDefault();
enableCoreChange();
});
});
demo jsFiddle
Note:
Instead of $('#selectmenu1, #selectmenu2, #selectmenu3'): starts with ^ selector:
$('select[id^="selectmenu"]').prop('disabled', false);
The attribute "disabled" does not need a value (backward compatibility) as soon as this attribute is available, it is disabled.
To activate it again use this function:
function enableCoreChange(){
alert('called');
$('#selectmenu1').removeAttr('disabled');
$('#selectmenu2').removeAttr('disabled');
$('#selectmenu3').removeAttr('disabled');
}
You should be using .prop() instead of .attr()
http://api.jquery.com/prop/
The problem here is you're specifying the string 'false' instead of the boolean false. Personally I'd use removeAttr for clarity
function enableCoreChange(){
alert('called');
$('#selectmenu1').removeAttr('disabled');
$('#selectmenu2').removeAttr('disabled');
$('#selectmenu3').removeAttr('disabled');
}
Fiddle: http://jsfiddle.net/6pznn/
I cannot get the following simple jQuery to work. I know I am overlooking something, so please help me out. Here is the code at http://jsfiddle.net/Z5waA/. It's a simple click the button, then alert with jQuery.
preventDefault(e); should be e.preventDefault();
code should be like this,
$('#submitResetPass').bind('click', function(e) {
e.preventDefault();
alert("hello");
});
and you need to add jQuery reference.
You had a couple issues. First, the jsFiddle wasn't set for jQuery. Then, your call to preventDefault wasn't correct. It works here: http://jsfiddle.net/jfriend00/v9aVb/.
$('#submitResetPass').bind('click', function(e) {
e.preventDefault();
alert("hello");
});
Use e.preventDefault() instead of preventDefault(e).