I have joomla module, in the module I have this jquery script, I want to show this javascript from js file in the of joomla but there is problem php variable how can I make this?


var container = $('.carmrg <?php echo $uniqid; ?>');
var first     = container.find('.img-log img').eq(0);
var ori     = container.find('.img-log a').eq(0);

container.find('.cars-img img').attr('src', first.attr('src'));
container.find('.cars-img a').attr('href', ori.attr('href'));

$('.img-log img').hover(function(){

    var $self  = $(this);
    var parent = $self.parents('.carmrg');

    parent.find('.cars-img img').attr('src', $self.attr('src'));
    parent.find('.img-log img').removeClass('active');

$('.img-log a').hover(function(){

    var $self  = $(this);
    var parent = $self.parents('.carmrg');

    parent.find('.cars-img a').attr('href', $self.attr('href'));
    parent.find('.img-log a').removeClass('active');

  'showImageNumberLabel': false,


  • I don't quote understand what you're saying or trying to do. Could you try explaining in a little more detail please?
    – Lodder
    Apr 18, 2016 at 17:34
  • sorry, for my bad english, ok Apr 18, 2016 at 17:36

1 Answer 1


Assuming you are asking how to combine PHP and JavaScript, one way would be to add the JavaScript inline via your module's PHP using this method, which will add it to the head of the page when the module is loaded.

$document = JFactory::getDocument();

If you need the js in a separate file, or the intention is to have multiple versions of this module on a page and this would create conflicts, then you could always search the DOM for any elements with a relevent class and create an array of their related IDs, which you can then loop through - not sure you need PHP for what you are trying to do.

Your Answer

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

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