*EDIT*
I have a feeling you're either coming from Prototype, or straight from DOM
scripting. I had the same preconceived notions when I first started with
jQuery...
So here is my attempt to do what you're trying to do (and from my testing,
it all works :))
$('#test textarea').each(function(){
//this refers to the current element
$(this).before('Current length:
<span>'+this.value.length+'</span> characters')
}) // Does NOT return the newly created item, but is still on the textarea
.keyup(function(){
//this refers to the current element
var max_length = this.id.split('_')[1];
var length_color = this.value.length > max_length ? 'red' : 'green';
var current_length = this.value.length || 0;
$(this).prev().html(current_length).css({color:length_color});
});
Daemach wrote:
>
> I'm trying to sort out a problem with a selector and I'm not having much
> luck. I'm using firebug at the moment, but I'm not able to easily see
> what the selector is picking up, if anything. The first selector is here:
>
> $('#test :textarea').before('Current length: <span id="'+ this.id
> +'_len">'+this.value.length+'</span> characters')
>
> <form action="boo" name="test" id="test">
> <textarea cols="54" rows="5" id="Desc_512"
> name="Description">SPORK</textarea>
> </form>
>
> BTW the documentation doesn't show a :textarea selector in the form
> section - should that be added or is that where I'm going wrong? I've
> tried using $("#Desc_512") as well and I'm still getting a "this.value has
> no properties" error. I'm not sure it's grabbing the right element :/
>
> It would be insanely useful to write a doc talking about tools and code
> snippets you could use to troubleshoot jquery stuff. Debugging hooks,
> like being able to pause and dump data (array contents, current dom
> element, etc) between chained functions would be great too. I'm a visual
> guy so being able to use something like dump()
> http://www.netgrow.com.au/files/javascript_dump.cfm
> http://www.netgrow.com.au/files/javascript_dump.cfm or sDumper() to see an
> object visually is hugely beneficial
>
> Is there a way to just return the jquery object (so I could see it in
> firebug's watch section) then pass it to another jquery function then join
> them all up when I know everything works?
>
>
> Here is the full function:
> ===================================
> $(document).ready(function(){
>
> $('#test :textarea').before('Current length: <span id="'+ this.id
> +'_len">'+this.value.length+'</span> characters').keypress(
> function() {
> $('#'+this.id + '_len').css('color', ((this.value.length >
> parseInt(this.id.split()[1]))?'red':'green')).html(this.value.length)
> } );
>
> });
>
> <form action="boo" name="test" id="test">
> <textarea cols="54" rows="5" id="Desc_512"
> name="Description">SPORK</textarea>
> </form>
>
> ===================================
>
--
View this message in context:
http://www.nabble.com/What-tools-should-I-use-to-troubleshoot-jquery-problems--%28John-Resig%2C-jquery-team%2C-other-gurus-please-share-your-tricks...%29-tf3066235.html#a8550126
Sent from the JQuery mailing list archive at Nabble.com.
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/