To achieve my goal as of this question How to apply a url path in after pseudo element? I want to assign a link to the menu item id.
Within php code I wrote this:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$item = $menu->getItem(474);
?>
and the jquery code is as you see is :
var $link = $('<a>',{
class: 'all-news-link',
href: <?php $item; ?> // **here how to assign the link which is assigned in php?**
});
$('#custom-module .moduletable:nth-child(2) h3').append($link);
update
As per the provided link I used json_encode but also not solved my problem. Its even not alerting now.
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
$link1 = $menu->getItem(474);
?>
<script>
$(document).ready(function(){
var $link = $('<a>',{
class: 'all-news-link',
href: <?php echo json_encode( $link1 ); ?>
});
$('#custom-module .moduletable:nth-child(2) h3').append($link);
alert("hi"); // it is not alerting
});
</script>
when href: 'http://www.google.com/' used its alerting "hi" but when I use php json_encode() its even not alerting means jquery is invalid