0

So I have this php code in my joomla site (joomla's latest article module) and id I'd like to add a bootstrap tooltip to the title of my links. Can someone point me in the right direction as to how i I add this script to a php page. Thanks in advance. Here's the script i got from w3schools.

<script>
$(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip();   
});
</script>

and my code which i already have.

<?php
defined('_JEXEC') or die;
?>
<div style="float: left;margin-right: 47px;">

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" data-toggle="tooltip" title="<?php   echo $item->title; ?>" itemprop="url"><img src="/images /sound.png" />&nbsp;
    <span itemprop="name">
        <?php echo $item->title; ?>
    </span>
</a>
</li>
<?php endforeach; ?>
</ul></div>

1 Answer 1

1

You should be able to add your jQuery code right after your existing code, but Joomla runs jQuery in noconflict mode, so you have to change $ to jQuery, or wrap your code like this:

<script>
  jQuery(document).ready(function ($) {
    $('[data-toggle="tooltip"]').tooltip();   
  });
</script>

Your entire code would look something like this:

<?php
defined('_JEXEC') or die;
?>
<div style="float: left;margin-right: 47px;">

<ul class="latestnews<?php echo $moduleclass_sfx; ?>">
<?php foreach ($list as $item) :  ?>
<li itemscope itemtype="http://schema.org/Article">
<a href="<?php echo $item->link; ?>" data-toggle="tooltip" title="<?php   echo $item->title; ?>" itemprop="url"><img src="/images /sound.png" />&nbsp;
    <span itemprop="name">
        <?php echo $item->title; ?>
    </span>
</a>
</li>
<?php endforeach; ?>
</ul></div>

<script>
  jQuery(document).ready(function ($) {
    $('[data-toggle="tooltip"]').tooltip();   
  });
</script>
1
  • Thanks for the reply. I just tried it but no luck. Not sure why. Anyways just so u know Im using the lastest articles module from joomla. Anything I might be missing? Thanks
    – Maestro J
    Sep 12, 2015 at 17:50

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.