I would like to split some content from an “a” html tag. I was starting over with jquery. My code is like this but it is not working:
$("a.uribb").each(function() {
var id = $(this).attr("href").replace("http://dereferer.org/?", "");
$(this).append(+id+);
});
And the HTML tag is this:
<a href="http://dereferer.org/?http://example.com/" target="_blank" class="uribb">
http://example.com/
</a>
I wanted to split out the http://dereferer.org/? part and leave the other there. How could I do this?
Try to use
.text()instead of.append()if you want to replace the content. Also, there is no need for the+before and after the id.You could try this instead:
Update
Reading through the question again, I’m not sure if you want to replace the content of the
a-tag or the the value of the href. In case of the latter, try this:Notice
Since jQuery 1.6, it is preferred to use .prop() instead of
.attr().