Olivier,

this.attr('name')
$(this.id)

In the first line you are trying to call the attr method on a DOM node 
(which is not defined), in the second you are passing a string (the id 
of the element this refers to) to the $ function, which returns an empty 
jQuery object, because there is element with the (tag) name of that id.

You have to distinguish between DOM nodes and jQuery objects.

You can either try $(this).id() or simply this.id, which will be better 
here performance-wise.


-- Klaus


Olivier Percebois-Garve schrieb:
> Seems that you are putting me on the way but
> $(this.id) outputs [object Object]
> 
> Onno Timmerman wrote:
>> Olivier Percebois-Garve schreef:
>>   
>>> Hi
>>>
>>> It seems that there is cases where it is not possible to get attributes. 
>>> How to deal with this ?
>>> $(this).val()  // works
>>> $(this).name() //not working
>>> $(this).id() //not working
>>>     
>>
>> more like $(this.id);
>>
>>   
>>> etc...
>>>
>>> Here is my code :
>>>
>>> $.fn.checkform = function() {    
>>>           this.bind("click", function(){
>>>                msg='';
>>>               
>>>                 $("input.check_empty").each(function(){
>>>                     if(this.value!='') {
>>>                         $(this).css("background", "#fff");
>>>                     } else {
>>>                      
>>>                       //alert($(this).name());   //breaks the script
>>>                       alert($(this).val());
>>>                      
>>>                       msg += 'is empty\n';
>>>                       $(this).css("background", "#ff0");
>>>                       $(this).after("<strong>is 
>>> empty</strong>");             
>>>                     };                   
>>>                 });                
>>>                  
>>>                 $("input.check_email").each(function(){
>>>                     if 
>>> (this.value.search(/^\w+((-\w+)|(\.\w+))[EMAIL 
>>> PROTECTED]((\.|-)\w+)*\.\w+$/) != -1) {
>>>                         $(this).css("background", "#fff");
>>>                     } else {
>>>                       msg += 'is not email\n';
>>>                       $(this).css("background", "#fff0ff");
>>>                       $(this).after("<strong>is not 
>>> email</strong>");            
>>>                     };                   
>>>                 }); 
>>>                  
>>>               alert("Please correct:\n"+msg);
>>>             if (msg!='') return false;
>>>             else return true;
>>>           });       
>>> };
>>>
>>>
>>> _______________________________________________
>>> jQuery mailing list
>>> [email protected]
>>> http://jquery.com/discuss/
>>>
>>>     
>>
>>
>>
>>
>>
>> _______________________________________________
>> jQuery mailing list
>> [email protected]
>> http://jquery.com/discuss/
>>
>>   
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to