I use the below code to get the id p:r:0:abc
to p\\:r\\:0\\:abc
function getId(comp) {
var id = comp.getClientId().split(':').join('\\\\:');
return id;
}
and I am using the generated id for the following
$(id).css("background-image", "url('../something.png')");
$(id).slideToggle();
it's not changing the background or doing the animation
But if I hard code the id as below its working fine
$(`#p\\:r\\:0\\:abc`).css("background-image", "url('../something.png')");
$(`#p\\:r\\:0\\:abc`).slideToggle();
Can you advice?
You have 1 too many \
in your join.
You only need 1 \
to escape the :
- p\:r\:0\:abc
.
var id = "p:r:0:abc".split(':').join('\\\:');
alert($('#' + id).text())
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<b id="p:r:0:abc">TEST</b>