Hi Blitze,

In your first example you'd need to wrap 'this' like $(this) in order to use
the .attr() method. I'm surprised the second example does not work.
By the way do you really want all the matched elements to be given the same
id? Typically the id of each element should be unique. For a common sort of
identifier one might use a classname instead.

Is your code snippit running within a jQuery ready() function? Eg:
$(function(){ ...your code... })

I'd have thought the following would work...

    $(function(){

        // Put all your jQuery code in this $.ready() handler.

        $('.shadow').attr("id", 'foo');

    })

George

PS: I have to ask...    is $('.shadow') actually returning any matches?!


Blitze wrote:
> 
> Hello,
> 
> I'm trying to dynamically set the id of all block elements found with
> class="shadow"  just like you can add a class dynamically using
> .addClass() but I've had no success. I've tried using:
> 
>       $('.shadow').each(function(){ this.attr("id", 'foo');});
> and
> 
>       $('.shadow').each(function(){ this.id = 'foo';});
> 
> but without any success. Would anyone be so kind to lend me a hand?
> 
> Thanks
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Set-Id-attribute-tf3384033.html#a9430078
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to