Thursday, 5 September 2013

jQuery change link href with .load()

jQuery change link href with .load()

I am trying to make a dropbox-like custom context menu. What I need is
that when the user right-clicks an element, the options such as "Edit" and
"Delete" that pop up in the context menu link to "edit" and "delete" for
that specific element. The context menu:
<div class="screenlock-transparent">
<div class="context-menu-wrapper">
<ul class="context-menu">
<a href="<?php echo $edit_url; ?>"><li><i class="icon-edit"
style="margin-right: 10px;"></i>Edit</li></a>
<a href="<?php echo $delete_url; ?>"><li><i class="icon-trash"
style="margin-right: 10px;"></i>Delete</li></a>
</ul>
</div>
</div>
The way I have gone about this is to user jQuery to fire an event when the
user right-clicks an element:
<script type="text/javascript">
$(document).ready(function(){
// Launch on-right-click on element
$(".custom-context-menu").mousedown(function(){
if(event.which == 3) {
if ($(this).hasClass("ul-all-years-faculty")) { // If on the
general faculty ul
// Load external php here to build url string specific to
the element
// Replace current href value with the url string produced
by the external php script
} else if ($(this).hasClass("ul-year-specific-faculty")) {
} else if ($(this).hasClass("ul-semester")) {
} else if ($(this).hasClass("ul-subject")) {
}
}
});
});
</script>
Where you see the quotes if the if statement is where I am trying to write
the code that will call my external php script and replace the href of
the, for example, "Edit" link in the context menu with an href of a url
containing variables specific to the element that was right-clicked.
I know how to use .load() for a div - $("#ID").load(...) will load in the
echoed content inside that div. However, what about loading inside the
href of a link (a) ?
Thank you so much. I greatly appreciate your help.

No comments:

Post a Comment