1

My JSON response is something like this:

{
          "description": "discription about the feaure will come here.  <a href=\"http://example.com\" target=\"_blank\">Learn more</a>",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature one"
        },
        {
          "description": "discription about the feaure will come here.",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature two"
        },
        {
          "description": "discription about the feaure will come here. ",
          "largeIconURL": "some_path/ico_someicon.gif",
          "displayName": "feature three"
        },

My template is something like this

<%
        _.each(items,function(item, key, list){
      %>
      <li>
        <div class="oneSpec">

          <div class="description">
            <h4><%= item.displayName %></h4>
            <p><%= item.description %></p>
          </div>
        </div>
      </li>

      <%
        });
      %>

How can i remove the anchor tag from description node before painting it to the DOM

1
  • To remove description definitely not write it! Commented Feb 19, 2014 at 11:06

2 Answers 2

0

I'm not entirely sure what you mean by "from description", but you can conditionally include something by using <% if (condition) {%>. I'm just guessing what you mean. If this is not it, you have to be more clear...

Update:

Remove the anchor like so (Regex in Javascript to remove links):

<%=item.description.replace(/<a\b[^>]*>(.*?)<\/a>/i,"")) %>
Sign up to request clarification or add additional context in comments.

2 Comments

one of my json node contains an <a> tag in it. I want to remove it. "description": "discription about the feaure will come here. <a href=\"http://example.com\" target=\"_blank\">Learn more</a>",
Check out this answer to remove links from a string: stackoverflow.com/questions/960156/… You can do all of this in the template or clean the json before passing it into the template.
0

One of the way is : After Rendering, Use


$(".description p a").remove(); //using jquery

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.