1

How do I convert this javascript selected to jQuery? I need to select a button class rather than an ID, and I understand the easiest way to do this is jQuery.

var playButton1 = document.getElementById("playButton1");

playButton1.onclick = function() {
    var ta = document.getElementById("playButton1");

    document['player'].receiveText1(ta.value);

    ta.value = ""
};
2
  • 3
    Have you read a jQuery tutorial? What is the problem? Commented Sep 24, 2011 at 0:35
  • 1
    Slightly off-topic, but why do you have the variable ta? Can't you just use your playButton1 variable instead? Commented Sep 24, 2011 at 0:38

6 Answers 6

2

Try the following. You didn't specify the new class name so I assumed it was "playButton".

$(document).ready(function() {
  $('.playButton').click(function() {
    document['player'].receiveText1(this.value);
    this.value = "";
  });
});
Sign up to request clarification or add additional context in comments.

Comments

0
var playButton1 = $("#playButton1");

playButton1.onclick = function() {
    var ta = playButton1.val();
    document['player'].receiveText1(ta);
    playButton1.val('');
};

Comments

0
$('#playButton1').click(function(){
    document['player'].receiveText1($('playerButton1').val());
    $('playerButton1').val('');
});

Comments

0
var playButton1 = $("playButton1");

playButton1.click(function() {
    var ta = $("playButton1");
    document['player'].receiveText1(ta.val());
    ta.val("");
});

Comments

0
<button class="playButton" value="1">Play 1</button>
<button class="playButton" value="2">Play 2</button>
<script type="text/javascript">
    $(function(){
        $(".playButton").click(function(){
            document['player'].receiveText1($(this).val());
        });
    });
</script>

Comments

0
$('#Class').click(function(e){
    document['player'].receiveText1(event.target.value);
    event.target.value = ""
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.