Hi,

I have such js code:

$(document).ready(function(){
	

	
	$('#a').click(function() {
		  alert('Handler for .click() called.');
		});
	
	
	
});

And I have a link in my page

<a id = "a" href="url">Link text</a>

I checked the view source of web page, scripts are loaded, my js file is called bannerUpload:

<script type="text/javascript" src="/joomla15/media/system/js/mootools.js"></script> 
  <script type="text/javascript" src="/joomla15/media/plg_jblibrary/jquery/jquery-1.3.2.min.js"></script> 
  <script type="text/javascript" src="/joomla15/includes/js/joomla.javascript.js"></script> 
  <script type="text/javascript" src="http://localhost/joomla15/components/com_banerioIkelimas/js/bannerUpload.js"></script> 
  <script type="text/javascript"> 
jQuery.noConflict();
  </script>

In view file I use this code to load my script:

<?php
	$document = &JFactory::getDocument();
	
	//$document->addScript(base_url().'media/js/libs/valums-ajax-upload/ajaxupload.js');
	$document->addScript( base_url().'components/com_banerioIkelimas/js/bannerUpload.js' );


?>

I get error

Uncaught TypeError: Cannot call method 'click' of null

Any idea why do I get that error?

Found the solution: I had to use jQyery instead of $ sign because they are conflickting with other libraries even when $.noConflict(); is called. E.g.

jQuery('#a').click(function() {
		  alert('Handler for .click() called.');
		});

But now the question - when I will use some libraries where the $ sigh is used instead of word jQuery, how will I be able to use them? Or I will have to use search and replace function in text editor to change those things?

Found :) when I use this:

$(document).ready(function($)

look, there is $ sign in brackets after word 'function' - it solves the issue :) now we can use libraries, they work, at least valums ajax upload library worked :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.