I am doing some experimenting (so the code below has lots of stuff that I wouldn't normally put in). I have pairs of spans (that have the same ID). In this exampel there are 2 with ID=42 and 2 with ID=43. Currently, when I click on the text of one of the ID=42s, both ID 42s highlight in red.
Using the plugin from http://arashkarimzadeh.com/index.php/jquery/7-editable-jquery-plugin.html, I added
$(function(){$('.test').editable()});
And that allows the text that is selected to become editable. What I want to do, is if ID=42 is clicked, the other ID=42 is editable -- not the one that is clicked. There will only ever be a max of two IDs with the same ID. What can I add to this code to loop through and make the change?
.selected { color:red; }
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.editable-1.3.3.js"></script>
<script type="text/javascript">
$(function(){$('.test').editable()});
$(".testClass").click(function () {
if ( $('.testClass').hasClass('selected') ) {
$('.testClass').removeClass('selected');
}
var thisTarget = $(this).attr('id');
$('#container').find('#'+thisTarget).toggleClass("selected", 1000);
return false;
});
</script>
<p>
<span id="42" class="testClass">
<span class="test">Click me (I need to turn red)</span>
</span>
</p>
<p>
<span id="43" class="testClass">
<span class="test">just another test</span>
</span>
</p>
<p>
<span id="42" class="testClass">
<span class="test">And I become editable</span>
</span>
</p>
<p>
<span id="43" class="testClass">
<span class="test">just another test</span>
</span>
</p>