How to access component methods from “outside” in ReactJS?

Why can’t I access the component methods from “outside” in ReactJS? Why is it not possible and is there any way to solve it? Consider the code: var Parent = React.createClass({ render: function() { var child = <Child />; return ( <div> {child.someMethod()} // expect “bar”, got a “not a function” error. </div> ); } … Read more

JavaScript DOM remove element

I’m trying to test if a DOM element exists, and if it does exist delete it, and if it doesn’t exist create it. var duskdawnkey = localStorage[“duskdawnkey”]; var iframe = document.createElement(“iframe”); var whereto = document.getElementById(“debug”); var frameid = document.getElementById(“injected_frame”); iframe.setAttribute(“id”, “injected_frame”); iframe.setAttribute(“src”, ‘http://google.com’); iframe.setAttribute(“width”, “100%”); iframe.setAttribute(“height”, “400”); if (frameid) // check and see if iframe … Read more

Get selected option text with JavaScript

I have a dropdown list like this: <select id=”box1″> <option value=”98″>dog</option> <option value=”7122″>cat</option> <option value=”142″>bird</option> </select> How can I get the actual option text rather than the value using JavaScript? I can get the value with something like: <select id=”box1″ onChange=”myNewFunction(this.selectedIndex);” > But rather than 7122 I want cat. 16 Answers 16

jQuery – Trigger event when an element is removed from the DOM

I’m trying to figure out how to execute some js code when an element is removed from the page: jQuery(‘#some-element’).remove(); // remove some element from the page /* need to figure out how to independently detect the above happened */ is there an event tailored for that, something like: jQuery(‘#some-element’).onremoval( function() { // do post-mortem … Read more

jQuery .live() vs .on() method for adding a click event after loading dynamic html

I am using jQuery v.1.7.1 where the .live() method is apparently deprecated. The problem I am having is that when dynamically loading html into an element using: $(‘#parent’).load(“http://…”); If I try and add a click event afterwards it does not register the event using either of these methods: $(‘#parent’).click(function() …); or // according to documentation … Read more

querySelector, wildcard element match?

Is there a way to do a wildcard element name match using querySelector or querySelectorAll? The XML document I’m trying to parse is basically a flat list of properties I need to find elements that have certain strings in their names. I see support for wildcards in attribute queries but not for the elements themselves. … Read more