[jQuery] When $(this) refers to what ?
Posted: Tue Oct 13, 2009 12:38 pm
Hi all
I have this jQuery code :
Here I have two functions, as u can see very similar, now the problem is that after some researches it seems that in the firs function $(this) refers to $("#menu").find('a') and in the second one $(this) refers to $('#messages').
Why am I thinking so ?
Cause I have this html code :
And when I am trying to access the input value with second function it is impossible, but when I am changing $('#messages') to $(".message") than I am accesing input value properly, can anybody explain me what is going why is that ?
And how can I access input value without changing this part $('#messages').load ?
I have this jQuery code :
Code: Select all
$(document).ready(function() { $("#menu").find('a').live("click",function() { $('body').load("index.php", {'mailbox': $(this).attr('value'), 'controller' : 'mailbox', 'action' : 'mailbox'}); }); $(".message").find('label').live("click",function() { $('#messages').load("index.php", {'id' : $(this).find('input').val(), 'controller' : 'mailbox', 'action' : 'message', 'repeat' : 'yes'}); });}); Why am I thinking so ?
Cause I have this html code :
Code: Select all
<div id="messages"> <div class="message"> {section name="i" loop=$parts} <label>{$parts[i].from}</label> <label>{$parts[i].id}<input type="hidden" value="{$parts[i].id}"></label> {/section} </div> </div> And how can I access input value without changing this part $('#messages').load ?