0

First time here ... Im a beginner in JS .

I want to display an input only when another input has a disabled attribute:

<button type="button" id="Last"> Last </button>
<button type="button" id="Go" style="display:none"> Go </button> 

after few click, and using jQuery, $("#Last").attr("disabled", "disabled"), I get (using the inspect tool) :

<button type="button" id="last" disabled="disabled"> Last </button>

I want to display this:

 <button type="button" id="Go" style="display:block"> Go </button>  

I tried this:

 $( document ).ready(function() {
  if($("#Last").prop('disabled', true)) {
        $('#Go').show();
  } else {
        $('#Go').hide();
  }
});

I doesn't work! Dont know where is the problem!

2 Answers2

0

You should show the button when the button is clicked. See the commented code below.

// When button is clicked
$("#last").on("click", function() {

  // Set button disabled to true
  $(this).prop("disabled", true);

  // Show the #go button
  $("#go").show();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button type="button" id="last"> Last </button>

<button type="button" id="go" style="display:none"> Go </button>

I have changed to ids to all lowercase. That is a good coding convention.

void
  • 36,090
  • 8
  • 62
  • 107
  • the `Last` button is set to `disabled` when it reach the last click (using jquery), I want to detect if that true, then display the second button – Jone Smith Feb 18 '18 at 15:00
  • @JoneSmith can you paste the piece of code in your question which is setting disabled property on the `#last button`? – void Feb 18 '18 at 15:03
  • Yes, `... if some conditions are correct, then do this ... $("#Last").attr("disabled", "disabled"), ... ` – Jone Smith Feb 18 '18 at 15:07
  • @JoneSmith then just add this line `$("#go").show();` just below `$("#Last").attr("disabled", "disabled")` and it should work just fine – void Feb 18 '18 at 15:11
0


as describe in the doc at this link http://api.jquery.com/prop/ the method prop(name, xxx) set the property name to the value xxx, o in your code the if statement is disabling the button last. You should use:
if($("#Last").prop('disabled')) $('#Go').show(); Be carefull that if you place this piece of code in $( document ).ready it only run once the page DOM is ready for JavaScript code to execute.

Short
  • 18
  • 4