Occumouctduex
New Member
So i have a html template: \[code\] <div style='background-color: red;'> <div> $QuestionUpButton <%--<img style="cursor: pointer" onclick="onAddQUestionVote" src="http://stackoverflow.com/Images/arrow-up-24-ns.png" data-questionvoteupbutton="$i" id='addQuestionVote' alt='Vote up' data-questionid='$questionUid' />--%> <span data-questionvotegroup='$i'>$QuestionVote</span> <span data-questiontextgroup='$i'>$textboxText<br /> </span> </div> <div id="mm" style='background-color: white;'> $AnswerUpVote <%--<img style="cursor: pointer" onclick="onAddAnswerVote" src="http://stackoverflow.com/Images/arrow-up-24-ns.png" data-answervoteupbutton="$i" id='addAnswerVote' alt='Vote up' data-answeruid='$answerGuid' />--%> <img style="cursor: pointer" onclick="onRemoveAnswerVote" src="http://stackoverflow.com/Images/arrow-down-24-ns.png" data-answervotedownbutton="$i" id='removeAnswerVote' alt='Vote down' data-answeruid='$answerGuid' /> <span data-answervotegroup='$i'>$AnswerVotes</span> <span data-labelgroup='$i'>Answer : </span> <span data-answertextgroup="$i" data-questionid='$questionUid' data-answerid="$answerGuid">$AnswerSpan</span> <input type='button' id='editButton' data-editlinkbuttongroup="$i" value='http://stackoverflow.com/questions/12763141/Edit' /> <input type='button' id='deleteButton' data-deletelinkbuttongroup="$i" value='http://stackoverflow.com/questions/12763141/Delete Question' /> </div> </div>\[/code\]on document load i run code where i replace all $ variables like this: \[code\]function MyFunction(result) { //console.log(result); var panel = $('#mypanel'); var userGuid = GetUserGuid().d; var panel = $('#MainContent_AnsweredQuestions_mypanel'); for (var k = 0; k < result.d.length; k++) { var notVotedQuestion = "<img style='cursor: pointer' onclick='onAddQUestionVote' src='http://stackoverflow.com/Images/arrow-up-24-ns.png' data-questionvoteupbutton='" + i + "' id='Img1' alt='Vote up' data-questionid='" + result.d[k].Uid + "' />"; var notVotedQuestion1 = "hulabula"; var notVotedAnswer = "notVotedAnswer"; var votedAnswer = ""; console.log(result.d[k].Uid) var html = $("#OwnerTemplateQuestionWithoutAnswer").html().replace(/\$i/g, i) .replace(/\$AnswerSpan/g, result.d[k].Answers[0].Conetent) .replace(/\$answerGuid/g, result.d[k].Answers[0].Uid) .replace(/\$questionUid/g, result.d[k].Uid) .replace(/\$QuestionVote/g, result.d[k].QuestionVotes.length) .replace(/\$AnswerVotes/g, result.d[k].Answers[0].AnswerVotes.length) .replace(/\$textboxText/g, result.d[k].Content); //var html1 = $("#OwnerTemplateQuestionWithoutAnswer").html(html); if (didUserVote(result.d[k], userGuid) == false){ html.html().replace("$AnswerUpVote", notVotedQuestion); } panel.append(html); i++; }}\[/code\]part where i replace first time is working great and exactly how i want:\[code\] var html = $("#OwnerTemplateQuestionWithoutAnswer").html().replace(/\$i/g, i) .replace(/\$AnswerSpan/g, result.d[k].Answers[0].Conetent) .replace(/\$answerGuid/g, result.d[k].Answers[0].Uid) .replace(/\$questionUid/g, result.d[k].Uid) .replace(/\$QuestionVote/g, result.d[k].QuestionVotes.length) .replace(/\$AnswerVotes/g, result.d[k].Answers[0].AnswerVotes.length) .replace(/\$textboxText/g, result.d[k].Content);\[/code\]but later in the code i need to load image differently depends on some conditions\[code\] if (didUserVote(result.d[k], userGuid) == false){ html.html().replace("$AnswerUpVote", notVotedQuestion); }\[/code\]and this part of cide doesnt work at all... Any suggestions on how to solve this, or how i can improve replacement in some kind of a way??