Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question
add comment

3 Answers

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!

share|improve this answer
add comment

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.

share|improve this answer
1  
I also think this could help. I usually replace every $ with jQuery, for example jQuery(this).find('tr') instead of $(this).find('tr') –  Ruben Herman Aug 1 '12 at 6:47
add comment

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');

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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