jQuery variable within a selector
html, jquery
Solution
You need to append the `x` variable to the string:
$(".mk[value='" + x + "']").each(function(key, value)
Also, you should note that `value` is not a valid attribute of `span`, so this code will cause validation issues.
Problem
I need `$('.mk[value=x]')` to work, but it does Not while `$('.mk[value=1]')` does. Please someone help ``` <body> <span class="mk" value="1">1</span> <span class="mk" value="1">1</span> <span class="mk" value="3">3</span> <input id="update" type="button" value="1" /> </body> <script type="text/javascript"> $('#update').click(function(){ var x = this.value //--> x =1 $('.mk[value=x]').each(function(key, value) { //--> NOT WORKING ! $('.mk[value=1]').each(function(key, value) { //--> WORKING ! $(this).replaceWith('<span class="mk" value="2">2</span>') }); }) </script> ```