use a href as a var in a jquery function -



use a href as a var in a jquery function -

i have function requires vars beingness appended div. 1 of vars href link onclick. how format link work in var within function? below not working.

what whole purpose of is

evaluate block of text. count , limit display 200 characters insert ahref link onclick before remainder of text throw span around remainder of text after link insert ahref link within span, right before closing span tag and insert of modified content in div

i've taken 2 snippets of code

1) trim text, , wrap in span jquery limit text length

2) show on click, hide on click http://girlswhogeek.com/tutorials/2007/show-and-hide-elements-with-javascript

and trying mash them come need. each snippet works on own.

this code have now:

<script type="text/javascript"> function showstuff(id) { document.getelementbyid(id).style.display = 'block'; } function hidestuff(id) { document.getelementbyid(id).style.display = 'none'; } $(function() { var limit = 200; var chars = $("#mydiv").text(); if (chars.length > limit) { var visiblepart = $("<div> "+ chars.substr(0, limit-1) + "</div>"); var readmore = $(<a href="#" onclick="showstuff('answer1'); homecoming false;">open</a>); var hiddenpart = $("<span id='answer1' style='display: none;'> " + chars.substr(limit-1) + "</span>"); var readless = $(<a href=\"#\" onclick=\"hidestuff('answer1'); homecoming false;\">close</a>); }); $("#mydiv").empty() .append(visiblepart) .append(readmore) .append(hiddenpart) .append(readless); } });

modified felix's version above both links weren't showing @ same time:

http://jsfiddle.net/cxw5d/4/

edit:

cleaned syntax 1 lastly time:

http://jsfiddle.net/cxw5d/5/

jquery function jquery-selectors

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -