Use html node from Javascript variable with jQuery?
I would like to use the attr() method on a html node, which I have a reference to in 开发者_C百科a normal variable in Javascript.
Now, the problem is that this node is not returned by a jQuery selector, but with normal Javascript: var myNode = window.getSelection().getRangeAt(0).commonAncestorContainer;
Now, I would like to do something like:
jQuery.attr(myNode, "style");
Obviousely, this does not work. Is there any way to use such jQuery method on a non-jQuery variable (a normal node)?
range.commonAncestorContainer
returns a DOM element just wrap it as a jQuery object, like this:
$(myNode)
For example:
var style = $(myNode).attr('style');
//or set it:
$(myNode).css('color', 'red');
精彩评论