Coast Line
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
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
....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;
}
}
}
});
});
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Guys
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.