Red
Red

Reputation: 6388

Text area event not working - jQuery

I have a problem with text area with jQuery. Please refer the following HTML.

<div class="CodeMirror">
    <div>
        <textarea autocapitalize="off" autocorrect="off" wrap="off">
        </textarea>
    </div>
</div>

the above text area doesn't have id,so with the help of jQuery i added it .

$('.CodeMirror').children().find('textarea').attr('id','new_editor');

i inspected through firebug and i can see "new_editor" as the id of that text area. But the problem is i cant attach any event/get values on that text area with id new_editor.

i also tried

$("#new_editor").live('click',function(){
    alert('test');
});

But not working ....that text area is dynamically generated by CodeMirror (codemirror.net).

Now i want to do some operation on that text area by using jQuery.

whats wrong with me ?? please help Thank you.

EDIT - Sorry,its not the problem actually that was a mistake [typing mistake,my real code is with # and not with $ sign]

Upvotes: 0

Views: 494

Answers (3)

Marco Johannesen
Marco Johannesen

Reputation: 13134

Hmm i pasted it into JSFIDDLE here http://jsfiddle.net/j7W7U/2/

And it seems to be working perfect... So make sure you don't have an error somewhere else, and check your console for errors :)


$("$new_editor").live('click',function(){ alert('test'); });

should be

$("#new_editor").live('click',function(){
alert('test');
});

You mistyped $ with # :)

Upvotes: 0

peirix
peirix

Reputation: 37751

That's because your selector is wrong. Switch $ with # in your selector:

$("#new_editor")....

Upvotes: 1

dknaack
dknaack

Reputation: 60496

You have the wrong selector. Try this. (# instead $)

$("#new_editor").live('click',function(){
    alert('test');
});

Upvotes: 2

Related Questions