javascript - li append function not work -
javascript - li append function not work -
i'm using blogger blogging platform. in blog homepage, create function grab images single post each post (there 5 posts in homepage), append images single post single slider, each post.
this function script (i place after <body>
tag):
<script type='text/javascript'> //<![cdata[ function striptags(s, n) { homecoming s.replace(/<.*?>/ig, "") .split(/\s+/) .slice(0, n - 1) .join(" ") } function rm(a) { var p = document.getelementbyid(a); img = p.getelementsbytagname("img").each( function(){ $(".flexslider .slides").append($("<li>").append(this)); }); p.innerhtml = '<div class="entry-container"><div class="entry-content"><div class="entry-image"><div class='flexslider'><ul class='slides'></ul></div></div><div class="entry-header"><h1><a href="' + y + '">' + x + '</a></h1></div><p>' + striptags(p.innerhtml, snippet_count) + '</p></div></div>' } //]]> </script>
then variable, each post have single variable, different each post based on it's id:
<script type='text/javascript'>var x="post title",y="http://myblog.url/post-url.html";rm("p8304387062855771110")
my single post markup:
<span id='p8304387062855771110'></span>
the problem is, append function in script not work. forget in code?
your jquery/javascript ropey. there no method each
on nodelist. seek not mix jquery/javascript much. , might consider using array/join on html want insert maintain line length readable. way might have noticed html quotes not consistent.1
var $p = $('#' + a); $p.find('img').each(function () { var html = $('<li>').append($(this)) $('.flexslider .slides').append(html); }); var html = [ '<div class="entry-container"><div class="entry-content">', '<div class="entry-image"><div class="flexslider">', '<ul class="slides"></ul></div></div><div class="entry-header">', '<h1><a href="', y, '">', x, '</a></h1></div><p>', striptags(p.innerhtml, snippet_count), '</p></div></div>' ].join(''); $p.html(html);
1 prefer single quotes js work , double quotes html attributes , never twain shall meet.
javascript jquery
Comments
Post a Comment