0

Been searching for a while so I came here to ask...

How can I print edit/create/delete node links with jQuery? I just want to show the links when I hover over the < li >'s. I already have the hover code... So I really just need to code to get the edit/create/delete node links.

Edit: So, not the current URL but fetch the ID/NID's. These are in a list. I want to show the edit/delete buttons of that specific article when hovering over an item.

Thanks in advance!

4 Answers 4

0

You need to see where you want these links. What you can do is, you can use drupal_add_js, to add a js variable, in drupal.settings, and thus use it as required. But for me, this is mainly useful when you have only one node on a page.

If you are showing multiple nodes, or a listing of nodes, you can add nodeID as an attribute to hidden input value, or div or span or any HTML element. As you said that you have the HOVER code, then you will have to get the value of a particular div/span/hidden field on which mousehover event is fired, and then take appropriate action.

Hope that helps.

0

If I understand correctly you need the urls to the node creation/edit/deletion. So, here it goes.

The link to add a node is:

node/add/your_content_type_name

to delete a node

node/node_id/delete

to edit a node

node/node_id/edit

You can fetch the node ID with jQuery from the url, But your kinda stuck with the content type name.

5
  • Thanks, I knew the links. But yes, how would I be able to fetch the node ID with jQuery?
    – 6olden
    Feb 7, 2013 at 13:19
  • Are you using node alias 'pathauto'? could you show me your links?
    – saadlulu
    Feb 7, 2013 at 13:22
  • Sorry, not using pathauto yet... I'm about to use it though but I was already far in development. Link is like this. I need to fetch ID... 29, 30 so on. /node/29/edit?destination=news Thanks for the help, appreciate it!
    – 6olden
    Feb 7, 2013 at 13:24
  • Then you could use this link to find your answer, jquery-howto.blogspot.com/2009/09/…
    – saadlulu
    Feb 7, 2013 at 13:31
  • I don't need to fetch the current URL by the way. It's a ul with li's and in those li's I want to add a edit/delete button to delete that specific article. So when I hover over it the edit/delete button appear.
    – 6olden
    Feb 7, 2013 at 15:14
0

If your question is for drupal 7, you already have this feature. It's called "contextual links", see this screenshot :
enter image description here

To see these links, you need to have sufficient permissions and you must print $title_suffix variable in your node template(s), eg.:

<?php print render($title_suffix); ?>

See this link for more details.

1
  • Thanks... But I want to add my own buttons so it's part of the design. I disabled the overlay and styled the forms also, so they appear on page.
    – 6olden
    Feb 7, 2013 at 15:22
0

So, I came up with my own solution with the help of you guys of course... It was very easy actually. I was thinking a bit too deep.

What I did:

I already added an edit link to the view... So I just added another delete link to the view. Both of them have a custom class. I used drupal_add_js to hide() and show() them. Pretty dumb...

Thanks for all the help, appreciate it! I can't upvote yet but will do as soon as I'm able to...

Your Answer

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

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