Thursday, 22 August 2013

Finding the closest spans id to replace the spans content

Finding the closest spans id to replace the spans content

I'm provably over complicating this so stop me if I'm going down a rabbit
hole. I'm trying to grab the id of a span when a checkbox is clicked and
then change the content in that span.
I've tried a few things and I think I'm on the right track, but as I said
I have a tendency to over complicate these things. By the way all the id's
are different and being set by a database id number.
I've tried this
var readInput = $(".check span").attr('id');
$('#'.readInput).text('Read');
Which kind of sort of works. Except it only grabs the first id even if I
am clicking on the third or forth checkbox....it also does not change the
text.
I've also tried just grabbing the span and then id that way, but that was
no way near what I need.
Any help would be wonderful!
the whole function looks like this... a lot of it is unnecessary for this
problem though.
$('.memo input.checkIt').on("click", function(){
var name_attr = $(this).attr('name');
var hidden_input = $('input[name="' + name_attr + '"]');
if($(this).siblings('a').attr("class") == 'checked') {
hidden_input.val(0);
}else {
hidden_input.val(1);
$(this).attr('disabled','disabled').parent().addClass('disabled');
var readInput = $(".check span").attr('id');
$('#' + readInput).text('Read');
console.log(readInput);
}
});

No comments:

Post a Comment