Skip to content

Instantly share code, notes, and snippets.

@Lasha
Created August 13, 2012 11:57
Show Gist options
  • Select an option

  • Save Lasha/3339977 to your computer and use it in GitHub Desktop.

Select an option

Save Lasha/3339977 to your computer and use it in GitHub Desktop.
Crazy DOM manipulation, store and parse old data, remove it, and append newly formatted to parent containers
$('.warfarin-box-right').each(function(index, element) {
$(this).find('p').each(function(i,el) {
var $currentParent = $(this).parent();
var medProp = $(el).html().split(':');
var medPropName = $('<span />', { "class" : "medPropLeft", text: medProp[0] + ":" });
var medPropDesc = $('<p />',
{ "class" : "medPropRight",
html: (function() {
var textToOutput = "";
for (var i = 0; i < medProp.length; i++) {
if (i === 0) continue;
textToOutput += medProp[i];
}
return textToOutput;
}())
});
$(el).remove();
$currentParent.append(medPropName).append(medPropDesc).append('<div class="clear"></div>');
// console.log($(this).parent(), medPropName, medPropDesc);
});
});
// THIS SCRIPT IT DESIGNED TO HANDLE MULTIPLE CONTAINERS OF CONTENT
/*
<div class="warfarin-box-right fltleft">
<div id="foi" class="block"><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Ethanol: Avoid ethanol (may enhance gastric mucosal irritation). </p><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Food: Ibuprofen peak serum levels may be decreased if taken with food. </p><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Herb/Nutraceutical: Avoid alfalfa, anise, bilberry, bladderwrack, bromelain, cat's claw, celery, chamomile, coleus, cordyceps, dong quai, evening primrose, fenugreek, feverfew, garlic, ginger, ginkgo biloba, ginseng (American, Panax, Siberian), grapeseed, green tea, guggul, horse chestnut seed, horseradish, licorice, prickly ash, red clover, reishi, SAMe (S-adenosylmethionine), sweet clover, turmeric, white willow (all have additional antiplatelet activity).</p></div>
</div>
<div class="clear"></div>
</div>
<div class="warfarin-box-right fltleft">
<div id="foi" class="block"><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Ethanol: Avoid ethanol (may enhance gastric mucosal irritation). </p><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Food: Ibuprofen peak serum levels may be decreased if taken with food. </p><p style="text-indent:-2em;margin-left:2em;text-align:justify;">Herb/Nutraceutical: Avoid alfalfa, anise, bilberry, bladderwrack, bromelain, cat's claw, celery, chamomile, coleus, cordyceps, dong quai, evening primrose, fenugreek, feverfew, garlic, ginger, ginkgo biloba, ginseng (American, Panax, Siberian), grapeseed, green tea, guggul, horse chestnut seed, horseradish, licorice, prickly ash, red clover, reishi, SAMe (S-adenosylmethionine), sweet clover, turmeric, white willow (all have additional antiplatelet activity).</p></div>
</div>
<div class="clear"></div>
</div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment