Conflicting JavaScripts

Help!!

I've got conflicting javascripts running on my site --

<script type="text/javascript">
var $ = jQuery.noConflict();
$(function(){
  $('label.supplierselect').click(function() {
    var cb = $('#' + $(this).attr('for'));
	if (cb.is(':checked')) {
		$(this).addClass('checked');
	}
	else {
		$(this).removeClass('checked');
	}
  });
});
</script>
<script type="text/javascript">
$(document).ready(function() {
	$('label').click(function() {
		$(this).closest('tr').find('.checked').removeClass('checked');
		$(this).addClass('checked');
	});
});
</script>

Open in new window


The first should only target labels with a class of supplierselect

The second should be targeting labels in a table with a class of tableodd which is in a form with an id of BrandRate.

The first works fine, until the second is added, once that happens the unselect fails...

Please advise.

Thank you
garethtnashAsked:
Who is Participating?
 
Julian HansenCommented:
Your second script is targeting all labels - it will include label.supplierselect as well - you need to either exclude that by using the not

$('label').not(''supplierselect').click ...

Or by adding something to distiinguish the too

$('.tableodd label').click ...
0
 
GaryCommented:
Should you not be specifying your class or target.
     $('.tableodd  label').click(function() {
          $(this).closest('tr').find('.checked').removeClass('checked');
0
 
garethtnashAuthor Commented:
Excellent Thank you Both
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.