1

I am having issues making a javascript work. Basically i just use this script for different web parts which have the .q1table class to insert some other classes.

I am getting an error uncaught type error Property $ of object[object window] is not a function.This works fine when the page is in normal mode but in edit mode it throws error.

can some one please tell me what am i doing wrong here.

 jQuery('.q1Table tr').each(function (index) {

   var $wp = $(this).find('tr:first');  ---this line throws the error

   var $1TR = $wp.closest('tr');
   $1TR.addClass("TitleBar");
   $1TR.removeClass('ms-Header');

Thanks

0

3 Answers 3

4

I can't garantee if this (only) solves your problem. At least this can be a tip for using jQuery within SharePoint.

One should avoid using $ for jQuery in SharePoint. It can conflict with SharePoint's other javascript objects like cmssitemanager as described in my blog post $ in cmssitemanager.js conflicts with $ in jQuery

I often disable $ for jQuery by running:

jQuery.noConflict();

Then only jQuery is available and $ doesn't conflict with SharePoint's $ objects. Hopefully, Microsoft won't use $ in their javascript code in the future.

1
  • 1
    I also think this could help. I usually replace every $ with jQuery, for example jQuery(this).find('tr') instead of $(this).find('tr') Aug 1, 2012 at 6:47
1

SharePoint has very specific instances where the $ namespace collides with one of SharePoint's JavaScript includes when you are in Page Edit mode and also in rare instances of FAST Search.

jQuery.noConflict(); is a great option, but you have to be careful when using it - if any other web parts are using jQuery and they reference the $(...) instead of jQuery(...), their code will stop functioning.

I have an article on my blog that deals with the jQuery.noConflict().

Another fun and safe way I've been using jQuery is by utilizing your own namespace:

$mine = jQuery.noConflict();
$mine('#myId').fadeIn();

Hope this helps!

0

If you want to use only first TR from your table. You can try other approach in JQuery which may be useful, like:

$(".q1Table tr:nth-child(1)").addClass("TitleBar");

$(".q1Table tr:nth-child(1)").removeClass('ms-Header');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.