user1074541
user1074541

Reputation: 191

automatically add node to href in query and cancel default

This is probably so simple to someone but cant figure it out. I have this code that shows a node in an alert box. How do I add this to the nodes href value ie www.example.com/connector/(nodes number). Also there seems to be a prevent default somehere that stops click events. How do I remove that?. Is there a simple way in jquery.

The code I have is below.

$("#demo")
    .bind("select_node.jstree", function (event, data) {
                       var selectedObj = data.rslt.obj;
        alert(selectedObj.attr("id") + selectedObj.attr("data"));

This produces the alert with node number.

From the source code I need to add to the href value below.

     <li id="node_80" rel="folder" class="jstree-closed"><ins class="jstree-icon">&nbsp;</ins><a href="#" class="jstree-clicked"><ins class="jstree-icon">&nbsp;</ins>TEST</a></li>

Upvotes: 1

Views: 212

Answers (2)

user1074541
user1074541

Reputation: 191

With thanks to Manatok.

I managed to get this working, by using jquery replace. adding

 .replace("node_","") ie selectedObjx.attr("id").replace("node_","")); 

I have added this in case anyone has similar problems. Many thanks for everyones help. – user1074541 Feb 27 at 22:03

Upvotes: 0

Manatok
Manatok

Reputation: 5706

Maybe something like this:

$("#demo")
    .bind("select_node.jstree", function (event, data) {
          var selectedObj = data.rslt.obj;
 $('.jstree-clicked').attr("href","www.example.com/connector/"+selectedObj.attr("id"));
          ...

Upvotes: 4

Related Questions