2
<script>
$(".box").bind("update",function(txt){
   alert(txt);
}); 


$(".box").trigger("update","Test text");
</script>


<div class="box" style="width:100px;">Nothing to say</div>

I want: alert "Test text".

I get: alert "[object Object]"

What is wrong?

http://jsfiddle.net/d5rdz71t/1/

1 Answer 1

6

First parameter of the event handler is the event object, so accept the data as the second parameter

$(".box").bind("update", function(event, txt) {
  alert(txt);
});

$(".box").trigger("update", "Test text");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="box" style="width:100px;">Nothing to say</div>

Sign up to request clarification or add additional context in comments.

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.