jquery - Error when trying to edit to check for class name duplicates -


i have following script working , needed add check no duplicate span classes appended.

original script below

    $.ajax({       type: "get",       url: location.protocol + '//' + window.location.hostname + '/%year%/export?type=league&l=%leagueid%&w=&json=1'       }).done(function (data) {       requiredstarters = data.league.starters.count;         $.get('http://%host%/%year%/options?l=%leagueid%&o=06', function (data) {          $(data).find('td.two_column_layout .report').each(function (index, element) {            if ($(this).find("td.player").length !== +requiredstarters && $(this).attr("id") !== "invalidlineup") {               var target = $("#invalidlineup").find("tbody");                 $(this).find("span a").each(function () {                    target.append("<tr class='oddtablerow'><td>" + $(this)[0].outerhtml + "</td><td class='lineupalert'><a class='lineuplink' href='http://%host%/%year%/options?league_id=%leagueid%&o=02&%franchiseid%'>submit valid lineup</a></td></tr>");                 });               }          });               var $lineuprow = $("#invalidlineup tr");                 if ($lineuprow.length == 1) {                  $lineuprow.text("all teams have valid lineups").addclass("oddtablerow").wrapinner("<td class='noevent'></td>");                 }               });     });   }); 

i need insert this

var clazz = {}; $(this).find("span a").each(function () {          var classname = this.classname;         if (clazz[classname]) {             return         }         clazz[classname] = true;         target.append("<tr class='oddtablerow'><td>" + $(this)[0].outerhtml + "</td><td class='lineupalert'><a class='lineuplink' href='http://%host%/%year%/options?league_id=%leagueid%&o=02&%franchiseid%'>submit valid lineup</a></td></tr>");     }) 

to replace this

        $(this).find("span a").each(function () {            target.append("<tr class='oddtablerow'><td>" + $(this)[0].outerhtml + "</td><td class='lineupalert'><a class='lineuplink' href='http://%host%/%year%/options?league_id=%leagueid%&o=02&%franchiseid%'>submit valid lineup</a></td></tr>");         }); 

but must doing wrong or not closing out , have no idea , new using jquery , need format change assume.

how instead:

$(this).find("span a").each(function () {     // class (assuming these items have 1 class)     var classname = $(this).attr('class');     // check more 1     if ($('.' + classname).length > 1) {         return;     } else {         target.append("the stuff you're appending");     } }); 

or alternate method similar started with:

var checkarray = []; $(this).find("span a").each(function (ind, ele) {     var classname = $(ele).attr('class');     if($.inarray(classname, checkarray) < 0){         checkarray.push(classname);         target.append("the stuff you're appending");     } }); 

Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -