jquery - Append HTML with Anchor Tags instead of Checkbox or Checkboxes Javascript -
i trying functional example of append html checkbox snippet work anchor tags well. thanks!
i have been working on months...
thanks can offer solution. i've been searching time.
sincerely, sean wichert, sr. :) 512-730-1069 (call me if solution well, & please leave voicemail it's google voice number use through gmail headset & don't typically have open unless need make call.
<!-- head starts here --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <!-- working javascript checkbox html output below --> <!-- need make work anchor tags question. --> <script type='text/javascript'>//<![cdata[ $(window).load(function(){ $('input[type="checkbox"]').click(function () { var title = $(this).closest('.pdt-checkbox').find('.html-code-insert').html(); var tempid = $(this).attr('id'); // if checkbox checked, add item ul. if($(this).prop('checked')){ var html = $("<li/>", { title: title, idholder: tempid, text: title }); $('ul.result').append(html); } else { // if checkbox unchecked, remove item ul. $('[idholder="' + tempid + '"]', 'ul').remove(); } }); });//]]> $.fn.selecttext = function () { return $(this).each(function (index, el) { if (document.selection) { var range = document.body.createtextrange(); range.movetoelementtext(el); range.select(); } else if (window.getselection) { var range = document.createrange(); range.selectnode(el); window.getselection().addrange(range); } }); } </script> <!-- body starts here --> <!-- working checkbox sample below --> <div class="pdt-checkbox"><input type="checkbox" id="pc-repair-step-one" value="yes" /><label for="pc-repair-step-one"> 1. smwn</label><div style="display:none;" title="#" class="html-code-insert">smwn</div></div> <!-- not working anchor attempt below --> <li class="addmenui"><a class="anchor" onclick="javascript:pcsecurityrepair();" href="#" id="pcsecrepair" value="yes">pc security repair</a><label for="pcsecrepair"></label><div title="#" style="display:none;" class="html-code-insert">smwn</div></li> <div onclick="$(this).selecttext()" style="background:url(button.jpg) 0 0 no repeat"; class="ctrl-a" alt="click me select notes."> <ul style=" font-size: 0px; margin-left: 5px; margin-top: 0px; padding: 20px; font-family: calibri, arial, sans-serif; font-weight: 700; line-height: 24px; text-shadow: 0px 1px 3px #999959; " class="result"> </ul> </div>
http://api.jquery.com/toggleclass/
you should use class toggle instead of value attribute
$('a.anchor').click(function () { $(this).toggleclass('clicked'); var title = $(this).parent().find('.html-code-insert').html(); var tempid = $(this).attr('id'); // if anchor clicked, add item ul. if ($(this).hasclass('clicked')){ var html = $("<li/>", { title: title, idholder: tempid, text: title }); $('ul.result').append(html); } else { // if anchor not clicked, remove item ul. $('[idholder="' + tempid + '"]', 'ul').remove(); }
Comments
Post a Comment