dom-manipulation

Remove element with jQuery but leave text

假如想象 提交于 2019-12-29 03:19:08
问题 I've got some html that looks like this: <div> <span class="red">red text</span> some more text <span class="blue">blue text</span> </div> What I want to do is use jQuery to remove all the spans within the div regardless of attached class, but leave the text within the span tags behind. So the final result will be: <div> red text some more text blue text </div> I've tried to use the unwrap() method but it unwraps the div. I've also tried to remove the elements but that removes the elements

Which is better: string html generation or jquery DOM element creation?

二次信任 提交于 2019-12-28 05:33:49
问题 Ok, I'm rewriting some vanilla JS functions in my current project, and I'm at a point where there's a lot of HTML being generated for tooltips etc. My question is, is it better/preferred to do this: var html = '<div><span>Some More Stuff</span></div>'; if (someCondition) { html += '<div>Some Conditional Content</div>'; } $('#parent').append(html); OR var html = $('<div/>').append($('<span/>').append('Some More Stuff')); if (someCondition) { html.append($('<div/>').append('Some

creating and removing <div> element in javascript

半腔热情 提交于 2019-12-23 19:57:13
问题 function labelOnClick () { function makeDivId(id) { return id + "_div"; }; var div = this.getElementById(makeDivId(this.id)); if (div) { div.parentNode.removeChild(div); } else { div = document.createElement("div"); div.innerHTML = "welcome"; div.id = makeDivId(this.id); this.appendChild(div); } } <label id="1" onclick="labelOnClick()" > BROWSER </label> <label id="2" onclick="labelOnClick()"> GAMING CONSOLE </label> In the above example, I'm trying to create a div element when a label is

Silverlight & Visual Tree Manipulation

不羁的心 提交于 2019-12-23 13:34:08
问题 Now this may be more trouble than it's worth but nevertheless, it'd be really useful to me right now. What I'd like to know is how I might go about manipulating the Silverlight visual tree at runtime. Doing simple things like adding and removing controls is easy enough but when you start having to traverse the tree with any reasonable amount of complexity I find myself yearning for a JQuery style syntax (LINQ would be pretty cool too I suppose) to handle DOM node replacements, movements and

Looping through array using a button

穿精又带淫゛_ 提交于 2019-12-23 04:28:54
问题 Ok, in essence I want to create a short quiz that has a next and previous button. I want to loop through two arrays, questions and choices, and have a score at the end. I have read chapters on the DOM and Events and it is just not clicking apparently. Really I need a little bit of code that shows a concrete example of how to manipulate the DOM. What I have so far are only the arrays, and a function declaring that x is in fact getting my element by id. haha. Sorry I don't have more code to

querySelectorAll: manipulating nodes

我只是一个虾纸丫 提交于 2019-12-22 04:13:10
问题 As far as I have understood, querySelector returns a real changeable element while querySelectorAll returns a non-live Static Node Set. I want to adjust the style of all elements fitting to a specific selector. It works fine for the first element with querySelector , but not for all matching elements with querySelectorAll . I guess that's because the node set is non-live. Is there a workaround? Or am I missing something? 回答1: The problem is that querySelector returns a single node.

Is there a JQuery DOM manipulator/CSS selector equivalent class in PHP?

爱⌒轻易说出口 提交于 2019-12-21 21:38:58
问题 I know that I can use DOMDocument and DOMXPath to manipulate XML files. But, I really love JQuery, and it would be great if there was something more like JQuery in the PHP world that I could use for sever side DOM manipulation. NOTE: I'm only interested here in how JQuery Selects and Manipulates the DOM, not all the other parts of JQuery (I guess you can say just the Pop and the Sizzle parts). Update: It looks like there is an equivalent for the selector functions, but as far as the

Is there anyway of getting javascript code injected in an iframe to execute without removing and reappending the script tag containing it?

女生的网名这么多〃 提交于 2019-12-21 20:43:00
问题 Context: I am building a live HTML,CSS & Javascript editor. It can be accessed here. The source can be accessed here. Question: Is it possible to run javascript code injected into an iframe without repeated removal and addition of <script> tag containing the code from and to the DOM tree? Since DOM manipulation is a costly affair, I want to try and eliminate multiple DOM manipulations. Instead I want to be able to just change the textContent of the <script> tag and have it run the new code

Building a web crawler - using Webkit packages

╄→尐↘猪︶ㄣ 提交于 2019-12-21 18:32:19
问题 I'm trying to build a web crawler. I need 2 things: Convert the HTML into a DOM object. Execute existing JavaScripts on demand. The result I expect is a DOM Object, where the JavaScript that executes on-load is already executed. Also, I need an option to execute on demand additional JavaScripts (on events like: onMouseOver , onMouseClick etc.) First of all, I couldn't find a good documentation source. I searched through Webkit Main Page but couldn't find much information for users of the

How to insert html text with text() function? [closed]

霸气de小男生 提交于 2019-12-20 07:49:37
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I need to change the content of an element which includes html. I tried with this, but the html tags are printed $('#content-sections label').text('my text <span>a span element</span>'); This is printed as it: my text <span>a span element</span> 回答1: You have to use html() for this. For example: $('#content