0

I am currently working on a graph application using d3.js. Following is the link to the d3-forced directed graph: https://bl.ocks.org/mbostock/4062045 If i create an on-click event for a node like:

node.on("click", function(d){
           console.log(d.id);
                         });

This even will print the names of nodes in the console of the developers tools of the browser. However I need to create a window in the html page(a widget) which will take this value and print it on clicking the node.

Is there any way to print the console output on html window widget(just another div)?

P.S. there is a similar question asked: how to make a output console using TextArea? But the answer is for determining the thresholding and not how to create it.

Help appreciated.

1
  • $('#somediv').append('<p>' + d.id + '</p>'); instead of console.log(), basically. Commented Mar 28, 2016 at 21:05

4 Answers 4

1


If you want to modify the page directly, in javascript you can use :

document.getElementById();

and there are a lot of different selectors you can see on here

Then to modify the HTML you only have to do like this :

document.getElementById("example").innerHTML = "test";

PS : if you use jquery you can use the $ function like this for example to do the same :

$("#example").html("test");

It uses the css selector so # means id.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Colas, this helped me!
1

Try opening a new window via javascript.

var myWindow = window.open("", "MsgWindow", "width=200, height=100");
myWindow.document.write(d.id);

2 Comments

I got it what you are trying to say. However, i want to create a console like application, similar to regular consoles which will print the events in the d3 graph. I tried using dialogue in HTML, but the dimensions and appearance is too bad, maybe i can change it later, however, is there a better way to do it?
@Omkar -- you can try using some js plugins like this one - dynamicdrive.com/dynamicindex8/dhtmlwindow
1

Like lynko said you can override console.log:

console.log = function (message) {
    //prettify message here
    $("#console_out_div").append("<p>" + message + "</p>");
};

console.log("test123");
console.log([1,3,4]);
console.log({a:"test", b: 2});

You just have to check the instanceof and typeof variable message and prettify the output. Something like this fiddle.

Comments

0

It's kludgey, but you could write console.log = customLogFunc; at the top of your script.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.