Q:

is there any way findout duplicate id name in the page using jquery

my script is :
$('document').ready(function () {  
    var position = 0; 
    var data = [{'id':'user1'},{'id':'user2'},{'id':'user3'},{'id':'user4'},{'id':'user5'}];  

    $('#add').click(function() {  
        var newdiv=$('<div></div>').attr('id', data[position].id).text(data[position].id);  
        $("#container").append(newdiv);  
        position++;position %= data.length;
    });  
});  

My html is:
<html>
    <body>  
        <button id="add">Add new div</button>  
        <div id="container"><div id="user3"></div></div>  
    </body>  
</html>   

when click a button i am appending new divs with some id name here before insert div i want to check all div id names if anything matches i don't want to append that div
my jsfiddle is here

A:

$("#add").click(function() {
    ...
    $.each(data, function(index, value) {
        $("<div />").attr('id', value.id).text(value.id).appendTo("#container"); 
    });
});

Please read the jQuery Cookbook. It'll help with the... headaches. 

