Search Results

Search found 22 results on 1 pages for 'bungle'.

Page 1/1 | 1 

  • "Access is denied" JavaScript error when trying to access the document object of a programmatically-

    - by Bungle
    I have project in which I need to create an <iframe> element using JavaScript and append it to the DOM. After that, I need to insert some content into the <iframe>. It's a widget that will be embedded in third-party websites. I don't set the "src" attribute of the <iframe> since I don't want to load a page; rather, it is used to isolate/sandbox the content that I insert into it so that I don't run into CSS or JavaScript conflicts with the parent page. I'm using JSONP to load some HTML content from a server and insert it in this <iframe>. I have this working fine, with one serious exception - if the document.domain property is set in the parent page (which it may be in certain environments in which this widget is deployed), Internet Explorer (probably all versions, but I've confirmed in 6, 7, and 8) gives me an "Access is denied" error when I try to access the document object of this <iframe> I've created. It doesn't happen in any other browsers I've tested in (all major modern ones). This makes some sense, since I'm aware that Internet Explorer requires you to set the document.domain of all windows/frames that will communicate with each other to the same value. However, I'm not aware of any way to set this value on a document that I can't access. Is anyone aware of a way to do this - somehow set the document.domain property of this dynamically created <iframe>? Or am I not looking at it from the right angle - is there another way to achieve what I'm going for without running into this problem? I do need to use an <iframe> in any case, as the isolated/sandboxed window is crucial to the functionality of this widget. Here's my test code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Document.domain Test</title> <script type="text/javascript"> document.domain = 'onespot.com'; // set the page's document.domain </script> </head> <body> <p>This is a paragraph above the &lt;iframe&gt;.</p> <div id="placeholder"></div> <p>This is a paragraph below the &lt;iframe&gt;.</p> <script type="text/javascript"> var iframe = document.createElement('iframe'), doc; // create <iframe> element document.getElementById('placeholder').appendChild(iframe); // append <iframe> element to the placeholder element setTimeout(function() { // set a timeout to give browsers a chance to recognize the <iframe> doc = iframe.contentWindow || iframe.contentDocument; // get a handle on the <iframe> document alert(doc); if (doc.document) { // HEREIN LIES THE PROBLEM doc = doc.document; } doc.body.innerHTML = '<h1>Hello!</h1>'; // add an element }, 10); </script> </body> </html> I've hosted it at: http://troy.onespot.com/static/access_denied.html As you'll see if you load this page in IE, at the point that I call alert(), I do have a handle on the window object of the <iframe>; I just can't get any deeper, into its document object. Thanks very much for any help or suggestions! I'll be indebted to whomever can help me find a solution to this.

    Read the article

  • Using JavaScript/jQuery to return a list of CSS selectors based on highlighted text

    - by Bungle
    I've been given some project requirements that involve (ideally) returning a list of CSS selectors based on highlighted text. In other words, a user could do something like this on a page: Click a button to indicate that their next text selection should be recorded. Highlight some text on the page. See a generated list of CSS selectors that correspond to all the elements that contain the highlighted text. Firstly, does this seem like a feasible goal? jQuery makes it easy to use a selector to access a particular element, but I'm not sure if the reverse holds true. If an element lacks an id attribute, I also don't know how you'd return an "optimized" selector - i.e., one that identifies an element uniquely. Maybe crawl up the DOM until you find an ID, then stem the selector from there? Secondly, from a high-level perspective, any ideas on how to go about this? Any tips or tricks that could speed development? I very much appreciate any help. Thanks!

    Read the article

  • Using a dynamic <script> (a <script> appended to the DOM by JavaScript) to load and initialize Click

    - by Bungle
    I'm creating an HTML/JavaScript widget to be used on third-party sites. This widget is generated by a <script> that our customers will insert on their page. The <script> creates an <iframe> in the customer's domain, and then creates and inserts all of that <iframe>'s content using JavaScript. It's important that this <iframe> contain Clicky's tracking code to monitor clicks on outbound links. Unfortunately, I'm not having any luck getting Clicky to work when I append the requisite <script> elements to the <iframe> using JavaScript. I first tried simply appending the Clicky tracking code to the <iframe> after appending some test outbound links, hoping that Clicky could attach to those automatically as it does on a static page. That didn't seem to work, so my next inclination was to use the "advanced_disable" custom option and use clicky.log() on the links I want to track. Here's a link to a test page that's along those lines: http://onespot.wsj.com/static/clicky_iframe_test.html When clicking a link on that test page, the action is not logged in Clicky, and a JavaScript error appears: clicky is not defined This ("clicky") appears to be defined in http://static.getclicky.com/js, which I confirmed through the Firebug console is indeed loading before I click a test outbound link. Has anyone successfully loaded Clicky in this way? If so, could you provide some sample code, a link to a working implementation, or some feedback on what's wrong with my code? I would also be interested to know if this is even possible. Thanks very much for any help or advice!

    Read the article

  • Any way to identify a redirect when using jQuery's $.ajax() or $.getScript() methods?

    - by Bungle
    Within my company's online application, we've set up a JSONP-based API that returns some data that is used by a bookmarklet I'm developing. Here is a quick test page I set up that hits the API URL using jQuery's $.ajax() method: http://troy.onespot.com/static/3915/index.html If you look at the requests using Firebug's "Net" tab (or the like), you'll see that what's happening is that the URL is requested successfully, but since our app redirects any unauthorized users to a login page, the login page is also requested by the browser and seemingly interpreted as JavaScript. This inevitably causes an exception since the login page is HTML, not JavaScript. Basically, I'm looking for any sort of hook to determine when the request results in a redirect - some way to determine if the URL resolved to a JSONP response (which will execute a method I've predefined in the bookmarklet script) or if it resulted in a redirect. I tried wrapping the $.ajax() method in a try {} catch(e) {} block, but that doesn't trap the exception, I'm assuming because the requests were successful, just not the parsing of the login page as JavaScript. Is there anywhere I could use a try {} catch(e) {} block, or any property of $.ajax() that might allow me to hone in on the exception or otherwise determine that I've been redirected? I actually doubt this is possible, since $.getScript() (or the equivalent setup of $.ajax()) just loads a script dynamically, and can't inspect the response headers since it's cross-domain and not truly AJAX: http://api.jquery.com/jQuery.getScript/ My alternative would be to just fire off the $.ajax() for a period of time until I either get the JSONP callback or don't, and in the latter case, assume the user is not logged in and prompt them to do so. I don't like that method, though, since it would result in a lot of unnecessary requests to the app server, and would also pile up the JavaScript exceptions in the meantime. Thanks for any suggestions!

    Read the article

  • Alternative to jQuery's .toggle() method that supports eventData?

    - by Bungle
    The jQuery documentation for the .toggle() method states: The .toggle() method is provided for convenience. It is relatively straightforward to implement the same behavior by hand, and this can be necessary if the assumptions built into .toggle() prove limiting. The assumptions built into .toggle have proven limiting for my current task, but the documentation doesn't elaborate on how to implement the same behavior. I need to pass eventData to the handler functions provided to toggle(), but it appears that only .bind() will support this, not .toggle(). My first inclination is to use a flag global to a single handler function to store the click state. In other words, rather than: $('a').toggle(function() { alert('odd number of clicks'); }, function() { alert('even number of clicks'); }); do this: var clicks = true; $('a').click(function() { if (clicks) { alert('odd number of clicks'); clicks = false; } else { alert('even number of clicks'); clicks = true; } }); I haven't tested the latter, but I suspect it would work. Is this the best way to do something like this, or is there a better way that I'm missing? Thanks!

    Read the article

  • Why does Google's Closure Compiler leave a few unnecessary spaces or line breaks?

    - by Bungle
    I've noticed that every time I use Google's Closure Compiler Service, it leaves a few unnecessary spaces in the compiled code presented on the right-hand side of the page. These correspond to line breaks in the hosted version of the compiled code. For example (note the line breaks, each of which seems unnecessary): http://troy.onespot.com/static/stack_overflow/closure_spaces.js To date, I've just been removing them manually, but I'm curious why they're there. Is it to limit the line length of the hosted version of the code to make it more readable? Could the compiler be smart enough to leave or insert those intentionally to maximize GZIP compression efforts? I know that they have a trivial effect on the file size, but with so much effort going into minifying every last byte in the source script, it's counterintuitive why they're there.

    Read the article

  • Binding event handlers to specific elements, using bubbling (JavaScript/jQuery)

    - by Bungle
    I'm working on a project that approximates the functionality of Firebug's inspector tool. That is, when mousing over elements on the page, I'd like to highlight them (by changing their background color), and when they're clicked, I'd like to execute a function that builds a CSS selector that can be used to identify them. However, I've been running into problems related to event bubbling, and have thoroughly confused myself. Rather than walk you down that path, it might make sense just to explain what I'm trying to do and ask for some help getting started. Here are some specs: I'm only interested in elements that contain a text node (or any descendant elements with text nodes). When the mouse enters such an element, change its background color. When the mouse leaves that element, change its background color back to what it was originally. When an element is clicked, execute a function that builds a CSS selector for that element. I don't want a mouseover on an element's margin area to count as a mouseover for that element, but for the element beneath (I think that's default browser behavior anyway?). I can handle the code that highlights/unhighlights, and builds the CSS selector. What I'm primarily having trouble with is efficiently binding event handlers to the elements that I want to be highlightable/clickable, and avoiding/stopping bubbling so that mousing over a (<p>) element doesn't also execute the handler function on the <body>, for example. I think the right way to do this is to bind event handlers to the document element, then somehow use bubbling to only execute the bound function on the topmost element, but I don't have any idea what that code looks like, and that's really where I could use help. I'm using jQuery, and would like to rely on that as much as possible. Thanks in advance for any guidance!

    Read the article

  • What's the most concise cross-browser way to access an <iframe> element's window and document?

    - by Bungle
    I'm trying to figure out the best way to access an <iframe> element's window and document properties from a parent page. The <iframe> may be created via JavaScript or accessed via a reference stored in an object property or a variable, so, if I understand correctly, that rules out the use of document.frames. I've seen this done a number of ways, but I'm unsure about the best approach. Given an <iframe> created in this way: var iframe = document.createElement('iframe'); document.getElementsByTagName('body')[0].appendChild(iframe); I'm currently using this to access the document, and it seems to work OK across the major browsers: var doc = iframe.contentWindow || iframe.contentDocument; if (doc.document) { doc = doc.document; } I've also see this approach: var iframe = document.getElementById('my_iframe'); iframe = (iframe.contentWindow) ? iframe.contentWindow : (iframe.contentDocument.document) ? iframe.contentDocument.document : iframe.contentDocument; iframe.document.open(); iframe.document.write('Hello World!'); iframe.document.close(); That confuses me, since it seems that if iframe.contentDocument.document is defined, you're going to end up trying to access iframe.contentDocument.document.document. There's also this: var frame_ref = document.getElementsByTagName('iframe')[0]; var iframe_doc = frame_ref.contentWindow ? frame_ref.contentWindow.document : frame_ref.contentDocument; In the end, I guess I'm confused as to which properties hold which properties, whether contentDocument is equivalent to document or whether there is such a property as contentDocument.document, etc. Can anyone point me to an accurate/timely reference on these properties, or give a quick briefing on how to efficiently access an <iframe>'s window and document properties in a cross-browser way (without the use of jQuery or other libraries)? Thanks for any help!

    Read the article

  • Will JavaScript evaluate a property's value if it's not part of an assignment statement?

    - by Bungle
    I've come across a fairly obscure problem having to do with measuring a document's height before the styling has been applied by the browser. More information here: http://sonspring.com/journal/jquery-iframe-sizing http://ajaxian.com/archives/safari-3-onload-firing-and-bad-timing In Dave Hyatt's comment from June 27, he advises simply checking the document.body.offsetLeft property to force Safari to do a reflow. Can I simply use the following statement: document.body.offsetLeft; or do I need to assign it to a variable, e.g.: var force_layout = document.body.offsetLeft; in order for browsers to calculate that value? I think this comes down to a more fundamental question - that is, without being part of an assignment statement, will JavaScript still evaluate a property's value? Does this depend on whether a particular browser's JavaScript engine optimizes the code?

    Read the article

  • JavaScript: Given an offset and substring length in an HTML string, what is the parent node?

    - by Bungle
    My current project requires locating an array of strings within an element's text content, then wrapping those matching strings in <a> elements using JavaScript (requirements simplified here for clarity). I need to avoid jQuery if at all possible - at least including the full library. For example, given this block of HTML: <div> <p>This is a paragraph of text used as an example in this Stack Overflow question.</p> </div> and this array of strings to match: ['paragraph', 'example'] I would need to arrive at this: <div> <p>This is a <a href="http://www.example.com/">paragraph</a> of text used as an <a href="http://www.example.com/">example</a> in this Stack Overflow question.</p> </div> I've arrived at a solution to this by using the innerHTML() method and some string manipulation - basically using the offsets (via indexOf()) and lengths of the strings in the array to break the HTML string apart at the appropriate character offsets and insert <a href="http://www.example.com/"> and </a> tags where needed. However, an additional requirement has me stumped. I'm not allowed to wrap any matched strings in <a> elements if they're already in one, or if they're a descendant of a heading element (<h1> to <h6>). So, given the same array of strings above and this block of HTML (the term matching has to be case-insensitive, by the way): <div> <h1>Example</a> <p>This is a <a href="http://www.example.com/">paragraph of text</a> used as an example in this Stack Overflow question.</p> </div> I would need to disregard both the occurrence of "Example" in the <h1> element, and the "paragraph" in <a href="http://www.example.com/">paragraph of text</a>. This suggests to me that I have to determine which node each matched string is in, and then traverse its ancestors until I hit <body>, checking to see if I encounter a <a> or <h_> node along the way. Firstly, does this sound reasonable? Is there a simpler or more obvious approach that I've failed to consider? It doesn't seem like regular expressions or another string-based comparison to find bounding tags would be robust - I'm thinking of issues like self-closing elements, irregularly nested tags, etc. There's also this... Secondly, is this possible, and if so, how would I approach it?

    Read the article

  • JavaScript: How to get text from all descendents of an element, disregarding scripts?

    - by Bungle
    My current project involves gathering text content from an element and all of its descendents, based on a provided selector. For example, when supplied the selector #content and run against this HTML: <div id="content"> <p>This is some text.</p> <script type="text/javascript"> var test = true; </script> <p>This is some more text.</p> </div> my script would return (after a little whitespace cleanup): This is some text. var test = true; This is some more text. However, I need to disregard text nodes that occur within <script> elements. This is an excerpt of my current code: // get text content of all matching elements for (x = 0; x < selectors.length; x++) { matches = Sizzle(selectors[x], document); for (y = 0; y < matches.length; y++) { match = matches[y]; if (match.innerText) { // IE content += match.innerText + ' '; } else if (match.textContent) { // other browsers content += match.textContent + ' '; } } } It's a bit overly simplistic in that it just returns all text nodes within the element (and its descendants) that matches the provided selector. The solution I'm looking for would return all text nodes except for those that fall within script elements. It doesn't need to be especially high-performance, but I do need it to ultimately be cross-browser compatible. I'm assuming that I'll need to somehow loop through all children of the element that matches the selector and accumulate all text nodes other than ones within <script> elements; it doesn't look like there's any way to identify JavaScript once it's already rolled into the string accumulated from all of the text nodes. I can't use jQuery (for performance/bandwidth reasons), although you may have noticed that I do use its Sizzle selector engine, so jQuery's selector logic is available. Thanks in advance for any help!

    Read the article

  • How do I pass a variable number of parameters along with a callback function?

    - by Bungle
    I'm using a function to lazy-load the Sizzle selector engine (used by jQuery): var sizzle_loaded; // load the Sizzle script function load_sizzle(module_name) { var script; // load Sizzle script and set up 'onload' and 'onreadystatechange' event // handlers to ensure that external script is loaded before dependent // code is executed script = document.createElement('script'); script.src = 'sizzle.min.js'; script.onload = function() { sizzle_loaded = true; gather_content(module_name); }; script.onreadystatechange = function() { if ((script.readyState === 'loaded' || script.readyState === 'complete') && !sizzle_loaded) { sizzle_loaded = true; gather_content(module_name); } }; // append script to the document document.getElementsByTagName('head')[0].appendChild(script); } I set the onload and onreadystatechange event handlers, as well as the sizzle_loaded flag to call another function (gather_content()) as soon as Sizzle has loaded. All of this is needed to do this in a cross-browser way. Until now, my project only had to lazy-load Sizzle at one point in the script, so I was able to just hard-code the gather_content() function call into the load_sizzle() function. However, I now need to lazy-load Sizzle at two different points in the script, and call a different function either time once it's loaded. My first instinct was to modify the function to accept a callback function: var sizzle_loaded; // load the Sizzle script function load_sizzle(module_name, callback) { var script; // load Sizzle script and set up 'onload' and 'onreadystatechange' event // handlers to ensure that external script is loaded before dependent // code is executed script = document.createElement('script'); script.src = 'sizzle.min.js'; script.onload = function() { sizzle_loaded = true; callback(module_name); }; script.onreadystatechange = function() { if ((script.readyState === 'loaded' || script.readyState === 'complete') && !sizzle_loaded) { sizzle_loaded = true; callback(module_name); } }; // append script to the document document.getElementsByTagName('head')[0].appendChild(script); } Then, I could just call it like this: load_sizzle(module_name, gather_content); However, the other callback function that I need to use takes more parameters than gather_content() does. How can I modify my function so that I can specify a variable number of parameters, to be passed with the callback function? Or, am I going about this the wrong way? Ultimately, I just want to load Sizzle, then call any function that I need to (with any arguments that it needs) once it's done loading. Thanks for any help!

    Read the article

  • How can I validate/secure/authenticate a JavaScript-based POST request?

    - by Bungle
    A product I'm helping to develop will basically work like this: A Web publisher creates a new page on their site that includes a <script> from our server. When a visitor reaches that new page, that <script> gathers the text content of the page and sends it to our server via a POST request (cross-domain, using a <form> inside of an <iframe>). Our server processes the text content and returns a response (via JSONP) that includes an HTML fragment listing links to related content around the Web. This response is cached and served to subsequent visitors until we receive another POST request with text content from the same URL, at which point we regenerate a "fresh" response. These POSTs only happen when our cached TTL expires, at which point the server signifies that and prompts the <script> on the page to gather and POST the text content again. The problem is that this system seems inherently insecure. In theory, anyone could spoof the HTTP POST request (including the referer header, so we couldn't just check for that) that sends a page's content to our server. This could include any text content, which we would then use to generate the related content links for that page. The primary difficulty in making this secure is that our JavaScript is publicly visible. We can't use any kind of private key or other cryptic identifier or pattern because that won't be secret. Ideally, we need a method that somehow verifies that a POST request corresponding to a particular Web page is authentic. We can't just scrape the Web page and compare the content with what's been POSTed, since the purpose of having JavaScript submit the content is that it may be behind a login system. Any ideas? I hope I've explained the problem well enough. Thanks in advance for any suggestions.

    Read the article

  • How do I add and remove an event listener using a function with parameters?

    - by Bungle
    Sorry if this is a common question, but I couldn't find any answers that seemed pertinent through searching. If I attach an event listener like this: window.addEventListener('scroll', function() { check_pos(box); }, false); it doesn't seem to work to try to remove it later, like this: window.removeEventListener('scroll', function() { check_pos(box); }, false); I assume this is because the addEventListener and removeEventListener methods want a reference to the same function, while I've provided them with anonymous functions, which, while identical in code, are not literally the same. How can I change my code to get the call to removeEventListener to work? The "box" argument refers to the name of an <iframe> that I'm tracking on the screen; that is, I want to be able to subscribe to the scroll event once for each <iframe> that I have (the quantity varies), and once the check_pos() function measures a certain position, it will call another function and also remove the event listener to free up system resources. My hunch is that the solution will involve a closure and/or naming the anonymous function, but I'm not sure exactly what that looks like, and would appreciate a concrete example. Hope that makes sense. Thanks for any help!

    Read the article

  • What is wrong with the JavaScript event handling in this example? (Using click() and hover() jQuery

    - by Bungle
    I'm working on a sort of proof-of-concept for a project that approximates Firebug's inspector tool. For more details, please see this related question. Here is the example page. I've only tested it in Firefox: http://troy.onespot.com/static/highlight.html The idea is that, when you're mousing over any element that can contain text, it should "highlight" with a light gray background to indicate the boundaries of that element. When you then click on the element, it should alert() a CSS selector that matches it. This is somewhat working in the example linked above. However, there's one fundamental problem. When mousing over from the top of the page to the bottom, it will pick up the paragraphs, <h1> element, etc. But, it doesn't get the <div>s that encompass those paragraphs. However, for example, if you "sneak up" on the <div> that contains the two paragraphs "The area was settled..." and "Austin was selected..." from the left - tracing down the left edge of the page and entering the <div> just between the two paragraphs (see this screenshot) - then it is picked up. I assume this has something to do with the fact that I haven't attached an event handler to the <body> element (where you're entering the <div> from if you enter from the left), but I have attached handlers to the <p>s (where you're entering from if you come from the top or bottom). There are also other issues with mousing in and out elements - background colors that "stick" and the like - that I think are also related. As indicated in the related question posted above, I suspect there is something about event bubbling that I don't understand that is causing unexpected behavior. Can anyone spot what's wrong with my code? Thanks in advance for any help!

    Read the article

  • Is it valid to have more than one question mark in a URL?

    - by Bungle
    I came across the following URL today: http://www.sfgate.com/cgi-bin/blogs/inmarin/detail??blogid=122&entry_id=64497 Notice the doubled question mark at the beginning of the query string: ??blogid=122&entry_id=64497 My browser didn't seem to have any trouble with it, and running a quick bookmarklet: javascript:alert(document.location.search); just gave me the query string shown above. Is this a valid URL? The reason I'm being so pedantic (assuming that I am) is because I need to parse URLs like this for query parameters, and supporting doubled question marks would require some changes to my code. Obviously if they're in the wild, I'll need to support them; I'm mainly curious if it's my fault for not adhering to URL standards exactly, or if it's in fact a non-standard URL.

    Read the article

  • How can I refactor this JavaScript code to avoid making functions in a loop?

    - by Bungle
    I wrote the following code for a project that I'm working on: var clicky_tracking = [ ['related-searches', 'Related Searches'], ['related-stories', 'Related Stories'], ['more-videos', 'More Videos'], ['web-headlines', 'Publication'] ]; for (var x = 0, length_x = clicky_tracking.length; x < length_x; x++) { links = document.getElementById(clicky_tracking[x][0]) .getElementsByTagName('a'); for (var y = 0, length_y = links.length; y < length_y; y++) { links[y].onclick = (function(name, url) { return function() { clicky.log(url, name, 'outbound'); }; }(clicky_tracking[x][1], links[y].href)); } } What I'm trying to do is: define a two-dimensional array, with each instance the inner arrays containing two elements: an id attribute value (e.g., "related-searches") and a corresponding description (e.g., "Related Searches"); for each of the inner arrays, find the element in the document with the corresponding id attribute, and then gather a collection of all <a> elements (hyperlinks) within it; loop through that collection and attach an onclick handler to each hyperlink, which should call clicky.log, passing in as parameters the description that corresponds to the id (e.g., "Related Searches" for the id "related-searches") and the value of the href attribute for the <a> element that was clicked. Hopefully that wasn't thoroughly confusing! The code may be more self-explanatory than that. I believe that what I've implemented here is a closure, but JSLint complains: http://img.skitch.com/20100526-k1trfr6tpj64iamm8r4jf5rbru.png So, my questions are: How can I refactor this code to make JSLint agreeable? Or, better yet, is there a best-practices way to do this that I'm missing, regardless of what JSLint thinks? Should I rely on event delegation instead? That is, attaching onclick event handlers to the document elements with the id attributes in my arrays, and then looking at event.target? I've done that once before and understand the theory, but I'm very hazy on the details, and would appreciate some guidance on what that would look like - assuming this is a viable approach. Thanks very much for any help!

    Read the article

  • What is the performance impact of CSS's universal selector?

    - by Bungle
    I'm trying to find some simple client-side performance tweaks in a page that receives millions of monthly pageviews. One concern that I have is the use of the CSS universal selector (*). As an example, consider a very simple HTML document like the following: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Example</title> <style type="text/css"> * { margin: 0; padding: 0; } </head> <body> <h1>This is a heading</h1> <p>This is a paragraph of text.</p> </body> </html> The universal selector will apply the above declaration to the body, h1 and p elements, since those are the only ones in the document. In general, would I see better performance from a rule such as: body, h1, p { margin: 0; padding: 0; } Or would this have exactly the same net effect? Essentially, what I'm asking is if these rules are effectively equivalent in this case, or if the universal selector has to perform more unnecessary work that I may not be aware of. I realize that the performance impact in this example may be very small, but I'm hoping to learn something that may lead to more significant performance improvements in real-world situations. Thanks for any help!

    Read the article

  • How do I remove elements from a jQuery wrapped set

    - by Bungle
    I'm a little confused about which jQuery method and/or selectors to use when trying to select an element, and then remove certain descendant elements from the wrapped set. For example, given the following HTML: <div id="article"> <div id="inset"> <ul> <li>This is bullet point #1.</li> <li>This is bullet point #2.</li> <li>This is bullet point #3.</li> </ul> </div> <p>This is the first paragraph of the article</p> <p>This is the second paragraph of the article</p> <p>This is the third paragraph of the article</p> </div> I want to select the article: var $article = $('#article'); but then remove <div id="inset"></div> and its descendants from the wrapped set. I tried the following: var $article = $('#article').not('#inset'); but that didn't work, and in retrospect, I think I can see why. I also tried using remove() unsuccessfully. What would be the correct way to do this? Ultimately, I need to set this up in such a way that I can define a configuration array, such as: var selectors = [ { select: '#article', exclude: ['#inset'] } ]; where select defines a single element that contains text content, and exclude is an optional array that defines one or more selectors to disregard text content from. Given the final wrapped set with the excluded elements removed, I would like to be able to call jQuery's text() method to end up with the following text: This is the first paragraph of the article.This is the second paragraph of the article.This is the third paragraph of the article. The configuration array doesn't need to work exactly like that, but it should provide roughly equivalent configuration potential. Thanks for any help you can provide!

    Read the article

  • Using jQuery to gather all text nodes from a wrapped set, separated by spaces

    - by Bungle
    I'm looking for a way to gather all of the text in a jQuery wrapped set, but I need to create spaces between sibling nodes that have no text nodes between them. For example, consider this HTML: <div> <ul> <li>List item #1.</li><li>List item #2.</li><li>List item #3.</li> </ul> </div> If I simply use jQuery's text() method to gather the text content of the <div>, like such: var $div = $('div'), text = $div.text().trim(); alert(text); that produces the following text: List item #1.List item #2.List item #3. because there is no whitespace between each <li> element. What I'm actually looking for is this (note the single space between each sentence): List item #1. List item #3. List item #3. This suggest to me that I need to traverse the DOM nodes in the wrapped set, appending the text for each to a string, followed by a space. I tried the following code: var $div = $('div'), text = ''; $div.find('*').each(function() { text += $(this).text().trim() + ' '; }); alert(text); but this produced the following text: This is list item #1.This is list item #2.This is list item #3. This is list item #1. This is list item #2. This is list item #3. I assume this is because I'm iterating through every descendant of <div> and appending the text, so I'm getting the text nodes within both <ul> and each of its <li> children, leading to duplicated text. I think I could probably find/write a plain JavaScript function to recursively walk the DOM of the wrapped set, gathering and appending text nodes - but is there a simpler way to do this using jQuery? Cross-browser consistency is very important. Thanks for any help!

    Read the article

  • How do I remove descendant elements from a jQuery wrapped set?

    - by Bungle
    I'm a little confused about which jQuery method and/or selectors to use when trying to select an element, and then remove certain descendant elements from the wrapped set. For example, given the following HTML: <div id="article"> <div id="inset"> <ul> <li>This is bullet point #1.</li> <li>This is bullet point #2.</li> <li>This is bullet point #3.</li> </ul> </div> <p>This is the first paragraph of the article</p> <p>This is the second paragraph of the article</p> <p>This is the third paragraph of the article</p> </div> I want to select the article: var $article = $('#article'); but then remove <div id="inset"></div> and its descendants from the wrapped set. I tried the following: var $article = $('#article').not('#inset'); but that didn't work, and in retrospect, I think I can see why. I also tried using remove() unsuccessfully. What would be the correct way to do this? Ultimately, I need to set this up in such a way that I can define a configuration array, such as: var selectors = [ { select: '#article', exclude: ['#inset'] } ]; where select defines a single element that contains text content, and exclude is an optional array that defines one or more selectors to disregard text content from. Given the final wrapped set with the excluded elements removed, I would like to be able to call jQuery's text() method to end up with the following text: This is the first paragraph of the article.This is the second paragraph of the article.This is the third paragraph of the article. The configuration array doesn't need to work exactly like that, but it should provide roughly equivalent configuration potential. Thanks for any help you can provide!

    Read the article

  • Do You Develop Your PL/SQL Directly in the Database?

    - by thatjeffsmith
    I know this sounds like a REALLY weird question for many of you. Let me make one thing clear right away though, I am NOT talking about creating and replacing PLSQL objects directly into a production environment. Do we really need to talk about developers in production again? No, what I am talking about is a developer doing their work from start to finish in a development database. These are generally available to a development team for building the next and greatest version of your databases and database applications. And of course you are using a third party source control system, right? Last week I was in Tampa, FL presenting at the monthly Suncoast Oracle User’s Group meeting. Had a wonderful time, great questions and back-and-forth. My favorite heckler was there, @oraclenered, AKA Chet Justice.  I was in the middle of talking about how it’s better to do your PLSQL work in the Procedure Editor when Chet pipes up - Don’t do it that way, that’s wrong Just press play to edit the PLSQL directly in the database Or something along those lines. I didn’t get what the heck he was talking about. I had been showing how the Procedure Editor gives you much better feedback and support when working with PLSQL. After a few back-and-forths I got to what Chet’s main objection was, and again I’m going to paraphrase: You should develop offline in your SQL worksheet. Don’t do anything in the database until it’s done. I didn’t understand. Were developers expected to be able to internalize and mentally model the PL/SQL engine, see where their errors were, etc in these offline scripts? No, please give Chet more credit than that. What is the ideal Oracle Development Environment? If I were back in the ‘real world’ of database development, I would do all of my development outside of the ‘dev’ instance. My development process looks a little something like this: Do I have a program that already does something like this – copy and paste Has some smart person already written something like this – copy and paste Start typing in the white-screen-of-panic and bungle along until I get something that half-works Tweek, debug, test until I have fooled my subconscious into thinking that it’s ‘good’ As you might understand, I don’t want my co-workers to see the evolution of my code. It would seriously freak them out and I probably wouldn’t have a job anymore (don’t remind me that I already worked myself out of development.) So here’s what I like to do: Run a Local Instance of Oracle on my Machine and Develop My Code Privately I take a copy of development – that’s what source control is for afterall – and run it where no one else can see it. I now get to be my own DBA. If I need a trace – no problem. If I want to run an ASH report, no worries. If I need to create a directory or run some DataPump jobs, that’s all on me. Now when I get my code ‘up to snuff,’ then I will check it into source control and compile it into the official development instance. So my teammates suddenly go from seeing no program, to a mostly complete program. Is this right? If not, it doesn’t seem wrong to me. And after talking to Chet in the car on the way to the local cigar bar, it seems that he’s of the same opinion. So what’s so wrong with coding directly into a development instance? I think ‘wrong’ is a bit strong here. But there are a few pitfalls that you might want to look out for. A few come to mind – and I’m sure Chet could add many more as my memory fails me at the moment. But here goes: Development instance isn’t properly backed up – would hate to lose that work Development is wiped once a week and copied over from Prod – don’t laugh Someone clobbers your code You accidentally on purpose clobber someone else’s code The more developers you have in a single fish pond, the greater chance something ‘bad’ will happen This Isn’t One of Those Posts Where I Tell You What You Should Be Doing I realize many shops won’t be open to allowing developers to stage their own local copies of Oracle. But I would at least be aware that many of your developers are probably doing this anyway – with or without your tacit approval. SQL Developer can do local file tracking, but you should be using Source Control too! I will say that I think it’s imperative that you control your source code outside the database, even if your development team is comprised of a single developer. Store your source code in a file, and control that file in something like Subversion. You would be shocked at the number of teams that do not use a source control system. I know I continue to be shocked no matter how many times I meet another team running by the seat-of-their-pants. I’d love to hear how your development process works. And of course I want to know how SQL Developer and the rest of our tools can better support your processes. And one last thing, if you want a fun and interactive presentation experience, be sure to have Chet in the room

    Read the article

1