tags:

views:

858

answers:

2

Is there any method to rename a div element. I have a div with id fm_form_container,which lists a set of forms. If I click a link in a tab,for eg, My Forms, I want the name of this fm_form_container to change as tab_content_container. That is, all my forms should come inside the div, tab_content_container.

Is there any method to rename a div,like append and addClass?

EDIT

These are the css for the div id "fm_myforms_container and tab_content_container.

.tab_content_container
 {
    width:100%;
    background-color:#FFFFE1;
    border:1px #EEEEEE solid;
 }

 #fm_myforms_container
 {
    width:100%;
    background-color:#FFF;
    border:1px #EEEEEE solid;
 }

If I give,

$('#myForms').click(function(){

    //$("#fm_myforms_container").attr("id", "tab_content_container");

    $("#fm_myforms_container").addClass("tab_content_container");

    viewAllMyForms();  

});

the CSS for tab_content_container does not get applied.

+4  A: 

You can use jQuery's attr method :

$("#fm_form_container").attr("id", "tab_content_container");
Toby Hede
Thank you.. But I have another problem. When I click the Home Tab again, I need the id to be changed to fm_form_container. I did a $("#tab_content_container").attr("id", "fm_form_container"); when I click 'Home'. But the div name is changed only for the first div n not for the seccond and third. I have separated my forms into 3 types,and so have them as three sections. So the change is happening only for the first section and not the others.
Angeline Aarthi
+5  A: 

Where the My Forms link has a class of "myForms":

$(".myForms").click(function () {
  $("#fm_form_container").attr("id", "tab_content_container");
});

Updated for comment to above answer:

*"$("#tab_content_container").attr("id", "fm_form_container"); when I click 'Home'. But the div name is changed only for the first div n not for the seccond and third."*

This is because you're matching against an ID (#), and thus will only match a single element. If you want to apply your changes to multiple elements, you will have to apply them to a class, e.g:

class="tab_content_container" instead of id="tab_content_container"
GlenCrawford
Well, I had the tab_content_container changed to a class and added the class to that div using addClass method. But the CSS aren't getting added..
Angeline Aarthi
Are you sure that you've changed your CSS to reflect the fact that your divs are now part of a class, rather than using ids?We'll need to see your CSS before we can diagnose that.
GlenCrawford