Deleting certain html blocks from HTML String - Javascript or Jquery -
i have html string looks follows :
<a href="#1">1</a> <a href="#a">a</a> <a href="#5">5</a> <a href="#4">4</a> i want write generalized function takes integer input. if, example input = 2, function should return html string this
<a href="#1">1</a> <a href="#a">a</a> if input parameters = 3
<a href="#1">1</a> <a href="#a">a</a> <a href="#5">5</a> and on. suggestions how can achieve ?
try this:
function getfirst(amount, str) { return $(str).slice(0, amount); } call this:
getfirst(2, '<a href="#1">1</a>' + '<a href="#a">a</a>' + '<a href="#5">5</a>' + '<a href="#4">4</a>') will result in:
<a href="#1">1</a><a href="#a">a</a>
Comments
Post a Comment