Sumit patel Sumit patel - 3 months ago 8
Javascript Question

get content between Custom Text

i want to text between

/*SumitStart*/
To
*SumitStart*/


HTML

<button type="button">Get Substring</button>
<div id="myid">
Hello My Div is large
/*SumitStart*/ hello chirag good morning welcome /*SumitEND*/ And Now End My DIv
sdfsdfsdfs
</div>


Script

$(document).ready(function(){
$("button").click(function(){
var data1 =$("#myid").text();
// alert(ss);
var subStr =$("#myid").text().match("/*SumitStart*/(.*)/*SumitEND*/");
alert(substr);
});
});


My Code HERE

Answer

You need to use Regular expression

var subStr = $("#myid").text().match(/\/\*SumitStart\*\/.*\/\*SumitEND\*\//);

DEMO