0
$('img').click(function () {
    $("#shikh_sec").attr("disabled", true); // doesn't work :/
    }

so , how to fix this and disable that element when clicking on the "img" tag

1
  • What version of jQuery are you using? Commented Sep 30, 2014 at 21:51

4 Answers 4

3

Assuming #shikh_sec is an input that can be disabled (there's no such thing as a disabled p element, etc.), you want prop():

$('#shikh_sec').prop('disabled', true);
Sign up to request clarification or add additional context in comments.

3 Comments

Note that this is limited to jQuery 1.6+
Hard to guess why not without knowing what the element is. Or if you might mean something different by 'disabled'. Or if the initial code is being run before the image in question has been added to the page. If you'd include sample code that actually shows the problem, we'd be better able to help.
For example, it works here: codepen.io/paulroub/pen/qmFoJ (having added the missing ) that someone pointed out).
1

The code is missing a trailing ");"

A correct version would be something like this

$('#disable-me').click(function () {
$(this).attr("disabled", true); // doesn't work :/
});

JSFiddle: http://jsfiddle.net/5v4mysgt/

2 Comments

The disabled attribute does not accept true as a value, you have to give it 'disabled' or use the prop setter if using jQuery 1.6+
It seems to be working for me, although it's proper to use $(this).attr("disabled", "disabled")
0

Try using disabled instead of true:

$('img').click(function () {
    $("#shikh_sec").attr("disabled", "disabled");
}

http://jsfiddle.net/yhfnzjuq/

$(function(){
  $('img').click(function () {
    $("#shikh_sec").attr("disabled", "disabled");
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="http://ichef.bbci.co.uk/news/ws/200/amz/worldservice/live/assets/images/2014/09/23/140923115528_ultima_hora_640x360_bbc_nocredit.jpg">
    
<input id="shikh_sec" type="button" value="OK">

Comments

-2

Or just with a pure javascript:

$('img').click(function () {
    document.getElementById("shikh_sec").disabled = true;
});

10 Comments

Downvoter .. you could leave some comment prior to downvoting the answer .. I hate haters
I would guess that the DV'er wanted to use the default reason for down-voting. It doesn't indicate hate. Having said that, you're not using "pure JavaScript".
Probably the use of $('img') in something labeled as "pure javascript". If you're using jQuery, why not keep using jQuery in the following line?
you solved it , thanq
This is just an alternative, if it doesn't deserve upvote it doesn't deserve downvote either, after all it works!
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.