I have the following:
<div class="tab-pane" id="message"> <textarea rows="4" cols="50" id="send_message" placeholder="Enter text ..."> </textarea> <a href="#message" class="btn btn-large btn-info" data-toggle="tab">OK</a> <a href="#message" class="btn btn-large btn-info" data-toggle="tab">Cancel</a> when I add:
if($(this).is(":contains(Cancel)")) { var text= $("#send_message").val(); log.console(text) I get the correct value
If I change the line to:
var text= $(this).find("#send_message").val(); I get undefined logged to console. Why is this?
Here is the full jQuery function:
$(function(){ $('#message').on("click", "a", function(){ if( $(this).is(":contains(OK)") ) { console.log("im in OK!!"); } else if( $(this).is(":contains(Cancel)") ) { // var text= $("#send_message").val(); var text= $(this).find("#send_message").val(); console.log(text); console.log("im in cancel!!"); } }); });
this?find()looks for elements below the DOM node you're currently in (in this case,$(this)refers to your lasta.btn.btn-large.btn-infolink). You want to use.closest()instead