Friday 15 May 2015

JQuery Looping a slice(), split(), and wrapped array...for each element of class -



JQuery Looping a slice(), split(), and wrapped array...for each element of class -

i'm pretty sure i'm close 1 can't seem right. im getting next strings dynamically each event listed, in same format. need split() off date each of these entries , homecoming times, split() @ ',' , rendered in spans i've got:

<div class="date">di 22.10.2014 um 14:00, 18:00</div> <div class="date">di 22.10.2014 um 14:00, 18:00, 20:00 </div>

and

var info =$('.date').html().slice(17); var arr = data.split(','); $(".date").empty(); $.each(arr, function(i, v) { $('.date').append($("<span>").html(v)); });

.... far good... http://jsfiddle.net/mealabmay/k3d6d/1088/ working, i've realised each '.date' ending same content. can't seem script converted each ... looked @ splitting text , wrapping each of words in elements in jquery , tried utilize same method....but sigh maintain drawing blank...any helpers out there? thx

use setter version of .text() takes callback function

class="snippet-code-js lang-js prettyprint-override">$('.date').each(function(i, text) { var $this = $(this), info = $this.text().slice(17); var arr = data.split(','); $this.empty(); $.each(arr, function(i, v) { $this.append($("<span>").html(v)); }); }) class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="date">di 22.10.2014 um 14:00, 18:00</div> <div class="date">di 22.10.2014 um 14:00, 18:00, 20:00</div>

probably way same

class="snippet-code-js lang-js prettyprint-override">$('.date').html(function(i, html) { homecoming $.map(html.trim().substring(17).split(','), function(item) { homecoming '<span>' + item + '</span>' }).join('') }) class="snippet-code-css lang-css prettyprint-override">.date span { border: 1px solid lightgrey; } class="snippet-code-html lang-html prettyprint-override"><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <div class="date">di 22.10.2014 um 14:00, 18:00</div> <div class="date">di 22.10.2014 um 14:00, 18:00, 20:00</div>

jquery split each slice

No comments:

Post a Comment