Basically, you use double quotes inside double quotes, this leads to invalidation of the attribute. You need to either change the encapsulating quotes to single quotes, or change the quotes inside the attribute value to single quotes.
Here is what I mean:
<div id="test" data-credit="<a href='http://example.com'>name</a>">
Here is a simple example that you can use for testing:
<head>
<script type="text/javascript">
$(document).ready(function() {
$("#v").val($("#test").attr("data-credit"));
});
</script>
</head>
<body>
<div id="test"
data-credit="<a href='http://example.com'>name</a>">
<input id="v" type="text" value="" />
</body>
</html>
Please note that using escaped html works .
source
share