[Javascript] Changing an Objects ID and Name

Terry Riegel riegel at clearimageonline.com
Wed Sep 6 09:44:44 CDT 2006


Roger, Jonathan, All,


An example page is at ...
http://clearimageonline.com/pages/start/projects/draganddrop/album.html

I am trying to build the part that will allow the user to swap images  
without a page reload. There may be a better way to do it that I am  
not thinking of. As far as swapping the drag and drop images I can do  
that with Walter Zorn's supplied methods, I need to change the images  
in the original HTML.

I will try Jonathan's suggestion as it sounds the most promising.


Thanks,

Terry

On Sep 6, 2006, at 9:52 AM, Roger Roelofs wrote:

> Terry,
>
> Without seeing the page, I can't tell if it would work for sure,  
> but, couldn't you just set the className and use css to get the  
> display you want?
>
> On Sep 6, 2006, at 9:34 AM, Terry Riegel wrote:
>
>> Sure, but then I would have an ID that represented the wrong  
>> image. And any subsequent manipulations with that image would be  
>> for the wrong ID.
>>
>> Swapping the src tag makes it look like it has swapped, but  
>> further javascript queries are going to be referencing the wrong  
>> ID, height, width, etc...
>>
>> Terry
>>
>>
>> On Sep 6, 2006, at 9:11 AM, Mike Dougherty wrote:
>>
>>> wouldn't it be easier just to swap their src attributes?
>>>
>>> On Wed, 6 Sep 2006 08:56:00 -0400
>>>  Terry Riegel <riegel at clearimageonline.com> wrote:
>>>> Hello,
>>>> I would like to swap out an image in an application I am  
>>>> writing.  Basically I want to swap two image tags, the trick is  
>>>> I want to swap  their ID and NAME tags also.
>>>> The important thing Is I would like to swap all of the  
>>>> attributes  out. i.e. width,height,id,name,src
>
> Roger





On Sep 6, 2006, at 10:20 AM, Jonathan Buchanan wrote:

> If you want to swap element locations (which is what you're really
> doing, if I've understood the question correctly), do it directly
> using the DOM instead of fiddling about with element attributes:
>
> function swapNodes(n1, n2)
> {
>    var placeHolder = document.createElement("span");
>    n1.parentNode.replaceChild(placeHolder, n1);
>    n2.parentNode.replaceChild(n1, n2);
>    placeHolder.parentNode.replaceChild(n2, placeHolder);
> }
>
> swapNodes(document.getElementById("abc"), document.getElementById 
> ("def"));
>
> Regards,
> Jonathan.






More information about the Javascript mailing list