Run jQuery on onclick button

Asked

Viewed 980 times

2

How to call jQuery direct on onclick button?, for example:

<input type="button" id="btnteste" onclick="$("#IDdoTextBox").spectrum("set", $("IDdoCampo").val());" />

And does not work, returns no error or anything. By the way, in Visual Studio itself is already in red as wrong code.

The way below works, but as I said I do not want, since everything will be created dynamically in ASP.NET

<script>
$("#btnteste").click(function() {
    $("#IDdoTextBox").spectrum("set", $("#IDdoCampo").val());
});

  • Just does not work or returns some error in the console?

  • I wonder if it is correct, because everything indicates that it is not so...there must be something missing...

3 answers

1


You are breaking the HTML syntax using "(double quotes) inside the onclick valve, try to use '(simple quotes).

Change of:

<input type="button" id="btnteste" onclick="$("#IDdoTextBox").spectrum("set", $("IDdoCampo").val());" />

for:

<input type="button" id="btnteste" onclick="$('#IDdoTextBox').spectrum('set', $('IDdoCampo').val());" />

1

0

Can be by quotation marks try using simple quotation marks like this:

<input type="button" id="btnteste" onclick="$('#IDdoTextBox').spectrum('set', $('IDdoCampo').val());" />
  • but when I do <script> I do it with the other quotes $("#btnEnterAColor"). click(Function() { $("#triggerSet"). Spectrum("set", $("#enterAColor"). val()); });

  • 1

    @Dorathoto Yes but like the reply our friend R3olon says: You are breaking the HTML syntax using "(double quotes)

  • 1

    perfect.. was that same...good the visual studio keeps showing the syntax in red. but it worked!.. thanks

  • @Dorathoto was worth it was a pleasure to help..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.