I have an script that when click a button do many things and also rename some elements, so at first I use first script and I see sometimes work, sometimes not, so change it to second script and all time worked perfectly, but there is a question. is this two scripts do same? what is the difference, rather than all of my script I just replace first one with second one.
This is first script
$(CloneTarget).find(':input[name="' + MainName + '"]').attr('name', NewSelectName);
And second one:
$(CloneTarget).find(':input').each(function () {
if ($(this).attr('name') == MainName) {
$(this).attr('name', NewSelectName);
}
});
Where is the problem with first one?
Edit
Also I use this:
$(CloneTarget).find(':input[id="' + MainId + '"]').attr('id', NewSelectId);
And every thing worked fine I am really confused here, I must mention MainName and MainId are so similar like: MainName = Model.Phones[0] and MainId = Model_Phones[0] is the difference is about . character or any other things?
.character may be mistaken for the start of a class selector, however it doesn't seem to be the case as of jQuery 1.7. Are you using an earlier version of the library?