Link to home
Start Free TrialLog in
Avatar of Coast Line
Coast LineFlag for Canada

asked on

appending and detaching elements jquery

Hi Experts

http://jsfiddle.net/Qgj52/2

It works fine, but only issue is when i use the default selected, it shows in the td, how can i detach it and attach it again, it does not work. remove is also not working as it completely removes the element, hide is not option here

please guide
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

I think you meant to use this link http://jsfiddle.net/Qgj52/2/

Unless somebody else understands this, I think I am confused as to what you want to do.

>how can i detach it and attach it again

Can you detail what you mean, I think I am missing something.
Avatar of Coast Line

ASKER

the code you have seen in the fiddle it works fine, now the issue is you see the default option as "Al Sections"

What i am trying is when i select from drop down any other value, it should reflect the th and the TD which is dynamicaaly created

Now, when i again do back forth and select "all selections" again, it should not display that column. and when i again choose another value, it should start again

i tried using hide, detach, remove but it does not work as expected
SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
....update....  I think this is what you want http://jsfiddle.net/Qgj52/4/

$(function () {
    var firstTime = true;

    $("#myselction").change(function (e) {
        var neData = $("#myselction").val();

        if (firstTime) {
            $("table.data thead tr").append("<th>Idea</th>");
            $("table.data tr:gt(0)").append("<td>" + neData + "</td>");
          firstTime = false;
        } else {
            if (neData!="All Selections(4)"){
            $("table.data tr:gt(0) td:last-child").html(neData);
        }else{
              var colCount = 0;
              $('tr:nth-child(1) td').each(function () {
              if ($(this).attr('colspan')) {
                  colCount += +$(this).attr('colspan');
              } else {
                 colCount++;
                }
              });
            
            if (colCount>2){
                $("table.data th:last-child, table.data td:last-child").remove(); 
             firstTime = true;
            } 
        }
            
        }
    });
});

Open in new window

third one seems good, only thing is: when i elect "All selections", it should remove the td of IDEA and when i choose again the dropdown value of 100 or 104, the IDEA td should appear again
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guys