0 votes
asked by (470 points)

 Hi guys.

I'm trying to do a simple onclick "disable" a button, but I can't seem to get it to work.  I've styled the button with a custom class "spell_button" and had hoped to target it with simple javascript to disable it once it has been clicked.

<span id="Test" class="spell_button"><<button "Test">>
    <<script>>
	    document.getElementById("Test").disabled = true;
    <</script>>
<</button>></span>

Any idea where I went wrong? :(

1 Answer

0 votes
answered by (55.3k points)
selected by
 
Best answer

The button doesn't have an id of test, the span you wrapped it in does. You need to target the button element itself: 

@@#test;<<button "test">>
    <<run $("#test button").prop("disabled", true)>>
<</button>>@@

You can use jQuery, it's included in SugarCube. 

commented by (470 points)
Ah.... thanks.  Works like a charm.  I'm not too well versed in Jquery, but i'll look it up.
Welcome to Twine Q&A, where you can ask questions and receive answers from other members of the community.

You can also find hints and information on Twine on the official wiki and the old forums archive.

See a spam question? Flag it instead of downvoting. A question flagged enough times will automatically be hidden while moderators review it.
...