Search Results

Search found 3639 results on 146 pages for 'dom manipulation'.

Page 2/146 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • DOM manipulation in PHP

    - by bluedaniel
    Hello everyone, Im trying to use the DOM in PHP to do a pretty specific job and Ive got no luck so far, the objective is to take a string of HTML from a Wordpress blog post (from the DB, this is a wordpress plugin). And then out of that HTML replace <div id="do_not_edit">old content</div>" with <div id="do_not_edit">new content</div>" in its place. Saving anything above and below that div in its structure. Then save the HTML back into the DB, should be simple really, I have read that a regex wouldnt be the right way to go here so Ive turned to the DOM instead. The problem is I just cant get it to work, cant extract the div or anything. Help me!! UPDATE The HTML coming out of the wordpress table looks like: Congratulations on finding us here on the world wide web, we are on a mission to create a website that will show off your culinary skills better than any other website does. <div id="do_not_edit">blah blah</div> We want this website to be fun and easy to use, we strive for simple elegance and incredible functionality.We aim to provide a 'complete package'. By this we want to create a website where people can meet, share ideas and help each other out. After several different (incorrect) workings all Ive got below is: $content = ($wpdb->get_var( "SELECT `post_content` FROM $wpdb->posts WHERE ID = {$article[post_id]}" )); $doc = new DOMDocument(); $doc->validateOnParse = true; $doc->loadHTMLFile($content); $element = $doc->getElementById('do_not_edit'); echo $element;

    Read the article

  • DOM manipulation

    - by bluedaniel
    Hello everyone, Im trying to use the DOM in PHP to do a pretty specific job and Ive got no luck so far, the objective is to take a string of HTML from a Wordpress blog post (from the DB, this is a wordpress plugin). And then out of that HTML replace <div id="do_not_edit">old content</div>" with <div id="do_not_edit">new content</div>" in its place. Saving anything above and below that div in its structure. Then save the HTML back into the DB, should be simple really, I have read that a regex wouldnt be the right way to go here so Ive turned to the DOM instead. The problem is I just cant get it to work, cant extract the div or anything. Help me!! UPDATE The HTML coming out of the wordpress table looks like: Congratulations on finding us here on the world wide web, we are on a mission to create a website that will show off your culinary skills better than any other website does. <div id="do_not_edit">blah blah</div> We want this website to be fun and easy to use, we strive for simple elegance and incredible functionality.We aim to provide a 'complete package'. By this we want to create a website where people can meet, share ideas and help each other out. After several different (incorrect) workings all Ive got below is: $content = ($wpdb->get_var( "SELECT `post_content` FROM $wpdb->posts WHERE ID = {$article[post_id]}" )); $doc = new DOMDocument(); $doc->validateOnParse = true; $doc->loadHTMLFile($content); $element = $doc->getElementById('do_not_edit'); echo $element;

    Read the article

  • Incorrectly formatted html inconsistencies between DOM and what's displayed in firefox plugin

    - by deadalnix
    I'm currently developing a firefox plugin. This plugin has to handle very crappy website that is really incorrectly formatted. I cannot modify these websites, so I have to handle them. I reduced the bug I'm facing to a short sample of html (if this appellation is appropriate for an horror like this) : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Some title.</title> <!-- Oh fuck yes ! --> <div style="visability:hidden;"> <a href="//example.com"> </a> </div> <!-- If meta are reduced, then the bug disapears ! --> <meta name="description" content="Homepage of Company.com, Company's corporate Web site" /> <meta name="keywords" content="Company, Company & Co., Inc., blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla" /> <meta http-equiv="Content-Language" content="en-US" /> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> </head> <body class="homePage"> <div class="globalWrapper"><a href="/page.html">My gorgeous link !</a></div> </body> </html> When opening the webpage, « My gorgeous link ! » if displayed and clickable. However, when I'm exploring the DOM with Javascript into my plugin, everything behaves (DOM exploration and innerHTML property) like the code was this one : <html> <head> <title>Some title.</title> <!-- Oh fuck yes ! --> </head><body><div style="visability:hidden;"> <a href="//example.com"> </a> </div> <!-- If meta are reduced, then the bug disapears ! --> <meta name="description" content="Homepage of Company.com, Company's corporate Web site"> <meta name="keywords" content="Company, Company &amp; Co., Inc., blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla, blablabla"> <meta http-equiv="Content-Language" content="en-US"> </body> </html> So, when exploring the DOM within the plugin, the document is somehow fixed by firefox. But this fixed DOM is inconsistent with what is in the webpage. Thus, my plugin doesn't behave as expected. I'm really puzzled with that issue. The problem exists in both firefox 3.6 and firefox 4 (didn't tested firefox 5 yet). For example, reducing the meta, will fix the issue. Where does this discrepancy come from ? How can I handle it ? EDIT: With the answer I get, I think I should be a little more precise. I do know what firefow is doing when modifying the webpage in the second code snippet. The problem is the following one : « In the fixed DOM that I get into my plugin, the gorgeous link doesn't appear anywhere, but this link is actually visible on the webpage, and works. So the DOM I'm manipulating, and the DOM in the webpage are different - they are fixed in a different manner. » . So where does the difference come in the fixing behaviour, and how can I handle that, or, in other terms, how can I be aware, in my plugin, of the existance of the gorgeous link ?

    Read the article

  • Best tool for DOM manipulation ?

    - by Olivier Lalonde
    I'm working on a web scraper which will aggregate data from various websites. I've started using PHP's built in DOM functions but after running into a couple of issues (especially regarding malformed markup and character encoding), I've chosen to ditch PHP. I was thinking of server side Javascript but am open to other suggestions. If I go with Javascript, which interpreter should I use?

    Read the article

  • window.onload seems to trigger before the DOM is loaded (JavaScript)

    - by Dr. Monkey
    I am having trouble with the window.onload and document.onload events. Everything I read tells me these will not trigger until the DOM is fully loaded with all its resources, it seems like this isn't happening for me: I tried the following simple page in Chrome 4.1.249.1036 (41514) and IE 8.0.7600.16385 with the same result: both displayed the message "It failed!", indicating that myParagraph is not loaded (and so the DOM seems incomplete). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <script type="text/javascript"> window.onload = doThis(); // document.onload gives the same result function doThis() { if (document.getElementById("myParagraph")) { alert("It worked!"); } else { alert("It failed!"); } } </script> </head> <body> <p id="myParagraph">Nothing is here.</p> </body> </html> I am using more complex scripts than this, in an external .js file, but this illustrates the problem. I can get it working by having window.onload set a timer for half a second to run doThis(), but this seems like an inelegant solution, and doesn't answer the question of why window.onload doesn't seem to do what everyone says it does. Another solution would be to set a timer that will check if the DOM is loaded, and if not it will just call itself half a second later (so it will keep checking until the DOM is loaded), but this seems overly complex to me. Is there a more appropriate event to use?

    Read the article

  • Chrome error with NO_MODIFICATION_ALLOWED_ERR DOM Exception 7

    - by HP
    I have below code to insert a style into DOM (there is a use case for injecting style into DOM so please don't ask why or say to load the css in .css file). <script type="text/javascript"> window.onload = function() { var bmstyle = document.createElement('style'); bmstyle.setAttribute('type', 'text/css'); var styleStr = "#test-div {background:#FFF;border:2px solid #315300;"; bmstyle.innerHTML = styleStr; document.body.appendChild(bmstyle); } </script> If I run in Firefox, it works fine. But I got this error in Google Chrome: Line bmstyle.innerHTML = styleStr; Uncaught Error: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7 Does anyone have a fix? Thanks

    Read the article

  • jQuery - How to remove a DOM element BEFORE complete page load

    - by webfac
    Now this may seem like a silly question, but I need to know how to remove a DOM element BEFORE it is displayed to the user. In short, I am using a div that has a background image alerting the user to enable javascript before proceeding. If the user has javascript enabled I am using jQuery to remove the DOM element, in this case $(".check-js") which is the div housing the image. Using the conventional methods to unload DOM objects as follows does not work because it waits for the page load to complete, then removes the element, causing the image to flicker on and off each time the page loads: $(function(){ $(".check-js").css( {display:"none"} ) }) I simply want to remove the div if the user has js enabled, and he must never see this div. Any suggestions and I will be grateful, thanks.

    Read the article

  • how to handle DOM in PHP

    - by From.ME.to.YOU
    my PHP code $dom = new DOMDocument(); @$dom->loadHTML($file); $xpath = new DOMXPath($dom); $tags = $xpath->query('//div[@class="text"]'); foreach ($tags as $tag) { echo $tag->textContent; } what i'm trying to do here is to get the content of the div that has class 'text' but the problem when i loop and echo the results i only get the text i can't get the HTML code with images and all the HTML tags like p, br,img... etc i tried to use $tag-nodeValue; but also nothing worked out any help !!?

    Read the article

  • How to get a reference to node in DOM tree in Google Chrome debugger console

    - by .yahoo.co.jpaqwsykcj3aulh3h1k0cy6nzs3isj
    In the Google Chrome debugger, I often want to get a reference to a node in the DOM tree. I can click the "magnifying glass" button and then click the desired element in the browser window to select the corresponding node in the DOM tree displayed in the debugger. But how can I get a reference to that node in the console? If the element has an id, document.getElementById works, but if there is no id, is there a better alternative to XPath or manual traversal of the DOM tree using children? In case XPath is the best way, is there a better way than doing something like this: var evaluator = new XPathEvaluator(); var result = evaluator.evaluate("//div", document.documentElement, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); which is a pain to type out each time.

    Read the article

  • jQuery: Trouble inserting DOM elements

    - by Rosarch
    I want to add a set of lists to the children of another DOM element: var req_subsets = $("#req_subsets"); $.each(subsets, function(index, subset) { var subset_list = $("<ul></ul>"); // add DOM elements to subset_list req_subsets.append(subset_list); }); However, only one DOM element is ever added. This makes me suspect that when I assign a new value to subset_list, the old one is overwritten. If that is the problem, how do I avoid it? If not, what else am I doing wrong? UPDATE: I changed something else, and I'm almost entirely certain that this is fixed.

    Read the article

  • Classic string manipulation interview questions?

    - by user189364
    Hi, I am scheduled to have an onsite interview so I am preparing few basic questions. According to the company profile, they are big on string manipulation questions. So far I have manually coded these functions: String length, copy, concat, remove white space Reverse Anagrams Palindrome Please can some can give me a list of more classic string questions which I can practice before going there?

    Read the article

  • jQuery filename manipulation

    - by Adi
    Hi all, I am trying to do a fancy blur/fade effect (which means i need 2 images) but I only want to load 1 in the HTML (in case js is not active) and add the other filename via jQuery (copying and renaming the file/src) The pure html is along the lines of: <div id="work"> <div> <img src="css/images/abc1.jpg" width="360" height="227" alt="" /> </div> <div> <img src="css/images/xyz1.jpg" width="360" height="227" alt="" /> </div> </div> But the html after jquery has manipulated the DOM needs to be like: <div id="work"> <div> <img src="css/images/abc0.jpg" width="360" height="227" alt="" /> <img src="css/images/abc1.jpg" width="360" height="227" alt="" /> </div> <div> <img src="css/images/xyz0.jpg" width="360" height="227" alt="" /> <img src="css/images/xyz1.jpg" width="360" height="227" alt="" /> </div> </div> The question is, what is the jQuery to clone/copy the relative images and then rename the src? Any help would be much appreicated. A.

    Read the article

  • Colour manipulation of custom tags in niceEdit HTML editor ( JS / DOM )

    - by Chris
    Hi, I would like to be able to highlight, during typing and in real time, certain custom tags in the format #tag_name# within the text of a nicEdit instance ( http://nicedit.com/ ). My current attempt to implement as close to this as possible revolves around using the blur event of the editor to highlight the tags once the editor loses focus. I then use the following logic to wrap the tags in a span with a highlight class.. htmlEditor.addEvent( "blur", function( ) { str = nicEditors.findEditor( "html_content" ).getContent( ); // Remove existing spans first, leaving just the tag ( this could mess up if the html has been edited directly ) str = str.replace( /(<span class=\"highlight\">)(.[^<]+)(<\/span>)/gi, "$2" ); // Then wrap all instances of a particular tag with the highlight span str = str.replace( /#tag_name#/gi, "<span class='highlight'>#tag_name#</span>" ); nicEditors.findEditor( "html_content" ).setContent( str ); }); This is not ideal as my actual text now contains unwanted spans ( I only want the highlighting for the user's input experience, not to be saved to the database ). Obviously I could remove the spans before saving the text but the whole system is currently open to errors ( If the html is directly edited then other text may get highlighted etc ). What I would like to know is.. Is there any way to directly change the colour of the tags in the editor or DOM without using a mechanism such as this? Perhaps a way of colouring the text in memory rather than changing the HTML ? Any ideas ? Regards Chris P

    Read the article

  • jQuery DOM manipulation

    - by ufw
    I have different php output in jQuery-based tabs. This output is formed from database and it consists of several <div>'s. Every time I click any tab it sends AJAX request to the php script which performs "SELECT" request and gives result back as response to AJAX request from the tab. $(document).ready(function() { $('ul.tabs li').css('cursor', 'pointer'); $('ul.tabs.tabs1 li').click(function(){ var thisClass = this.className.slice(0,2); $('div.t1').hide(); $('div.t2').hide(); $('div.t3').hide(); $('div.t4').hide(); $('div.' + thisClass).show('fast'); $('ul.tabs.tabs1 li').removeClass('tab-current'); $(this).addClass('tab-current'); var data = thisClass; $.ajax({ type:"GET", url:"handler.php?name="+data, data:data, success:function(html) { $('div.' + thisClass).html(html); } }); return false; }); }); //Server-side PHP script: <?php $name = $_GET[name]; switch ($name) { case "t1": query_and_output_1(); case "t2": query_and_output_2(); // etc... } ?> The problem is that the first tab contains output that must be in second and third ones as well, the second also contains the third tab output. Sorry for such a rubbishy question, I used to work with server side and unfortunately I'm not familiar with DOM and jQuery yet. Thanks.

    Read the article

  • Prototype or jQuery for DOM manipulation (client-side dynamic content)

    - by luiggitama
    I need to know which of these two JavaScript frameworks is better for client-side dynamic content modification for known DOM elements (by id), in terms of performance, memory usage, etc.: Prototype's $('id').update(content) jQuery's jQuery('#id').html(content) BTW, both libraries coexist with no conflict in my app, because I'm using RichFaces for JSF development, that's why I can use "jQuery" instead of "$". I have at least 20 updatable areas in my page, and for each one I prepare content (tables, option lists, etc.), based on some user-defined client-side criteria filtering or some AJAX event, etc., like this: var html = []; int idx = 0; ... html[idx++] = '<tr><td class="cell"><span class="link" title="View" onclick="myFunction('; html[idx++] = param; html[idx++] = ')"></span>'; html[idx++] = someText; html[idx++] = '</td></tr>'; ... So here comes the question, which is better to use: // Prototype's $('myId').update(html.join('')); // or jQuery's jQuery('#myId').html(html.join('')); Other needed functions are hide() and show(), which are present in both frameworks. Which is better? Also I'm needing to enable/disable form controls, and to read/set their values. Note that I know my updatable area's id (I don't need CSS selectors at this point). And I must tell that I'm saving these queried objects in some data structure for later use, so they are requested just once when the page is rendered, like this: MyData = {div1:jQuery('#id1'), div2:$('id2'), ...}; ... div1.update('content 1'); div2.html('content 2'); So, which is the best practice?

    Read the article

  • Feedback on "market manipulation", a peripheral game mechanic for a satirical MMO

    - by BerndBrot
    This question asks for feedback on a specific game-mechanic. Since there is not one right feedback on a game mechanic, I tried to provide enough context and guidelines to still make it possible for users to rate answers and to accept an answer as the best answer (following these criteria from Writer.SE's meta website). Please comment if you have any suggestions on how I could improve the question in that regard. So, let's begin with the game itself and some of its elements which are relevant for this question. Context I'm working on a satirical, text-based multiplayer adventure and role-playing game set in modern-day London. The game resolves around the concept of sin and features a myriad of (venomous) allusions to all the things that go wrong in this world. Players can choose between character classes like bullshit artist (consultant), bankster, lawyer, mobster, celebrity, politician, etc. In order to complete the game, the player has to live so sinfully with regard to any of the seven deadly sins that a demon is willing to offer them a contract of sponsorship. On their quest to live a sinful live, characters explore more and more locations of modern-day London (on a GoogleMap), fight "monsters" like insurance sales agents or Jehovah's Witnesses, and complete quests, like building a PowerPoint presentation out of marketing buzz words or keeping up a number of substance abuse effects in order to progress on the gluttony path. Battles are turn based with both combatants having a deck of cards, with which they try to make their enemy give in to temptations of all sorts. Tempted enemies sometimes become contacts (an item drop mechanic), which can be exploited for various benefits, depending on their area of influence (finance, underworld, bureaucracy, etc.), level of influence, and kind of sway that the player has over them (bribed, seduced, threatened, etc.) Once a contract has been exploited, the player loses that contact. Most actions require turns. Turns are limited, but refill each day. Criteria A number of peripheral game mechanics are supposed to represent real world abuses and mischief in a humorous way integrate real world data and events to strengthen the feeling of relevance of the game's humor with regard to real world problems add fun ways of interacting with other players add ways for players to express themselves through game-play Market manipulation is one such peripheral game mechanic and should fulfill all of these goals. Market manipulation This is my initial design of the mechanic: Players can enter the London Stock Exchange (LSE) (without paying a turn) LSE displays the stock prices of a number of companies in industries like weapons or tobacco as well as some derivatives based on wheat and corn. The stock prices are calculated based on the actual stock prices of these companies and derivatives (in real time) any market manipulations that were conducted by the players any market corrections of the system Players can buy and sell shares with cash, a resource in the game, at current in-game market value (without paying a turn). Players can manipulate the market, i.e. let the price of a share either rise or fall, by some amount, over a certain period of time. Manipulating the market requires 1 turn A contact in the financial sector (see above). The higher the level of influence of the contact, the stronger the effect of the manipulation on the stock price, and/or the shorter it takes for the manipulation to manifest itself. Market manipulation also adds a crime to the player's record. (There are a multitude of ways to take care of that, but it is still another "cost" of market manipulations.) The system continuously corrects market manipulations by letting the in-game prices converge towards their real world counterparts at a rate of 2% of the difference between the two per hour. Because of this market correction mechanism, pushing up prices (and screwing down prices) becomes increasingly difficult the higher (lower) the price already is. Whenever food prices reach a certain level, in-game stories are posted about hunger catastrophes happening somewhere far, far away (maybe with links to real world news stories). Whenever a player sells a certain number of shares with a sufficiently high margin, they are mentioned in that day's in-game financial news. Since the number of stock options is very limited, players will inevitably collide in their efforts to manipulate the market in their favor. Hopefully, it will also be a fun side-arena for guilds and covenants to fight each other. Question(s) What do you think of this mechanism given the criteria for peripheral game mechanics that I specified for my game? Do you have any ideas how the mechanic could be improved with regard to these criteria (or otherwise)? Could it be improved to allow for more expressive game-play, or involve an allusion to some other real world madness (like short selling, leveraging, or some other banking magic)? Are there any game-theoretic problems with this mechanic, like maybe certain dominant individual strategies that, collectively, lead to every player profiting and thus eliminating the idea of market manipulation PVP? Also, if you like (or dislike) this question, feel free to participate in the discussion on GDSE meta: "Should we be more lax with regard to SE's question/answer format to make game design questions possible?"

    Read the article

  • What do the FireBug DOM colors mean?

    - by André Pena
    I'm confused with these colors. I noticed there are 4 colors showing in the left hand column of FireBug DOM tree: Bold black Black Bold green Green In the right hand column: Blue Red Bold green Green Multiple color elements representing object structures. What do this colors represent? And why, e.g, I can access window.document.URL and I can't access window.document.body in Console even though they are both in the "not-bold black" category in the DOM tree? Thanks a lot

    Read the article

  • jQuery Adding DOM Elements

    - by Aren B
    This may be a simple answer, but I'm trying to add a dom-created element (i.e. document.createElement(...)) to a jQuery Selector. jQuery has a great assortment of functions for adding html .html(htmlString) .append(htmlString) .prepend(htmlString) But what i want to do is add a dom OBJECT var myFancyDiv = document.createElement("div"); myFancyDiv.setAttribute("id", "FancyDiv"); // This is the theoretical function im looking for. $("#SomeOtherDiv").htmlDom(myFancyDiv);

    Read the article

  • referencing DOM elements in jQuery

    - by Lyon
    Hi, I would select multiple DOM elements using a typical code such as this: $('#ele1, #ele2, #ele3').click(function () {}); If I have variables of each DOM element, e.g. var domEle1 = $('#ele1'); var domEle2 = $('#ele2'); var domEle3 = $('#ele3'); How can I select them all at once? Instead of individually... domEle1.click(function () {}); Thanks!

    Read the article

  • Javascript: getting element in dom tree when mouseover

    - by oimoim
    Hi, When using : document.onmouseover = function(e) {} Is there a property which gives me the element in the dom tree ? For example, I can set a style to e.srcElement But, how can I later access this element to (for example) reset its style ? And how can I know at which place in the dom tree it is ? I want to be able to situate it in the whole page dump. Many thanks.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >