Ok so I have an element with radio buttons, and I clone this element when an add button is clicked; however, once I do so, the button on the initial element is unchecked. I know why this happens, but once I began to implement a work around it doesn't do as I expect.
Here was my solution:
//This stores the value of the checked element into a variable before the clone
var radioKeep = $('input.event'+(numOfParts-1)+':checked').val();
//Cloned the element passed into the function
$(element).parent().clone(true, false).insertAfter($(element).parent());
Then after the clone I try to make sure the initial radio button is re-checked with the following combination of jquery and xpath.
$('input.event'+(numOfParts-1)+'[@value='+radioKeep+']').attr('checked', 'checked');
The result is that all radio elements are checked... why???
Thanks in advance.
console.log(radioKeep +' -- ' + numOfParts), do these values ever change? If not, then your selector will match every cloned element, and you also never clear the value, so the value will always match. Seems like this is most likely the issue. Can you get a jsFiddle up?0eve change on successful clicks? Or is it 0 everytime? if so, then all elements will have that class everytime and that's 1/2 of my thoughts, now does the value ofradioKeepever change?