<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>DOM &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Sat, 11 Apr 2020 17:10:02 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>DOM &#8211; MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>How to parse and process HTML/XML in PHP</title>
		<link>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/</link>
					<comments>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Wed, 15 Apr 2020 16:44:00 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[String Manipulation Algorithms]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[find-html]]></category>
		<category><![CDATA[grabbing]]></category>
		<category><![CDATA[html-manipulation]]></category>
		<category><![CDATA[html-parser]]></category>
		<category><![CDATA[libxml]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parser]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[parsing-html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-class]]></category>
		<category><![CDATA[php-extension]]></category>
		<category><![CDATA[php-query]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[php7]]></category>
		<category><![CDATA[query-path]]></category>
		<category><![CDATA[simple-html-dom]]></category>
		<category><![CDATA[simple-xml]]></category>
		<category><![CDATA[xml-parser]]></category>
		<category><![CDATA[xml-reader]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=239</guid>

					<description><![CDATA[Simple HTML DOM is a great open-source parser: simplehtmldom.sourceforge It treats DOM elements in an object-oriented way, and the new iteration has a lot of coverage for non-compliant code. There are also some great functions like you&#8217;d see in JavaScript, &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/" aria-label="How to parse and process HTML/XML in PHP">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>Simple HTML DOM is a great open-source parser:</p>



<p><a href="http://simplehtmldom.sourceforge.net/">simplehtmldom.sourceforge</a></p>



<p>It treats DOM elements in an object-oriented way, and the new iteration has a lot of coverage for non-compliant code. There are also some great functions like you&#8217;d see in JavaScript, such as the &#8220;find&#8221; function, which will return all instances of elements of that tag name.</p>



<p>I&#8217;ve used this in a number of tools, testing it on many different types of web pages, and I think it works great.</p>



<p>These are the main features:</p>



<ul><li>HTML DOM parser written in PHP 5+ that lets you manipulate HTML in a very easy way</li><li>Require PHP 5+</li><li>Supports invalid HTML</li><li>Find tags on an HTML page with selectors just like jQuery</li><li>Extract contents from HTML in a single line</li></ul>



<p><strong>How to get HTML elements:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from URL or file
$html = file_get_html('http://www.example.com/');

// Find all images
foreach($html-&gt;find('img') as $element)
       echo $element-&gt;src . '&lt;br&gt;';

// Find all links
foreach($html-&gt;find('a') as $element)
       echo $element-&gt;href . '&lt;br&gt;';</pre></div>



<p><strong>How to modify HTML elements:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from string
$html = str_get_html('&lt;div id=&quot;hello&quot;&gt;Hello&lt;/div&gt;&lt;div id=&quot;world&quot;&gt;World&lt;/div&gt;');

$html-&gt;find('div', 1)-&gt;class = 'bar';

$html-&gt;find('div[id=hello]', 0)-&gt;innertext = 'foo';

echo $html;</pre></div>



<p><strong>Extract content from HTML:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Dump contents (without tags) from HTML
echo file_get_html('http://www.google.com/')-&gt;plaintext;</pre></div>



<p><strong>Scraping Slashdot:</strong></p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;php&quot;,&quot;mime&quot;:&quot;text/x-php&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;PHP&quot;,&quot;modeName&quot;:&quot;php&quot;}">// Create DOM from URL
$html = file_get_html('http://slashdot.org/');

// Find all article blocks
foreach($html-&gt;find('div.article') as $article) {
    $item['title']     = $article-&gt;find('div.title', 0)-&gt;plaintext;
    $item['intro']    = $article-&gt;find('div.intro', 0)-&gt;plaintext;
    $item['details'] = $article-&gt;find('div.details', 0)-&gt;plaintext;
    $articles[] = $item;
}

print_r($articles);</pre></div>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-parse-and-process-html-xml-in-php/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">239</post-id>	</item>
		<item>
		<title>Set “top,left” of an element with the position relative to the parent in jQuery</title>
		<link>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/</link>
					<comments>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Sat, 11 Apr 2020 14:00:00 +0000</pubDate>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[coordinates]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css-left]]></category>
		<category><![CDATA[css-top]]></category>
		<category><![CDATA[document]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-element]]></category>
		<category><![CDATA[jquery-offset]]></category>
		<category><![CDATA[jquery-position]]></category>
		<category><![CDATA[jquery-positioning]]></category>
		<category><![CDATA[left]]></category>
		<category><![CDATA[offset]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[position]]></category>
		<category><![CDATA[position-relative]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=213</guid>

					<description><![CDATA[The .offset([coordinates]) method set the coordinates of an element but only relative to the document. Then how can we set coordinates of an element but relative to the parent? The.position() method get only &#8220;top,left&#8221; values relative to the parent, but &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/" aria-label="Set “top,left” of an element with the position relative to the parent in jQuery">Read More</a>]]></description>
										<content:encoded><![CDATA[
<p>The <code>.offset([coordinates])</code> method set the coordinates of an element but only relative to the document. Then <strong>how can we set coordinates of an element but relative to the parent</strong>?</p>



<p>The<code>.position()</code> method get only &#8220;top,left&#8221; values relative to the parent, but it doesn&#8217;t set any values, so the following code doesn&#8217;t work: </p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">$(&quot;#mydiv&quot;).css({top: 200, left: 200});</pre></div>



<p>Instead, to set the position relative to the parent, we need to set the <code>position:relative</code> of parent and <code>position:absolute</code> of the element, like in the following piece of code:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">$(&quot;#mydiv&quot;).parent().css({position: 'relative'});
$(&quot;#mydiv&quot;).css({top: '200px', left: '200px', position:'absolute'});</pre></div>



<p>This works because <code>position: absolute;</code> positions relatively to the closest <strong>positioned</strong> parent (the closest parent with any position property other than the default <code>static</code>).</p>



<p><strong>Just a reminder: set values correctly in jQuery!</strong> </p>



<p>In jQuery if the value passed is a string type, it must be followed by &#8216;px&#8217; (i.e. <span class="has-inline-color has-virtue-primary-color"><em>&#8217;90px&#8217;</em></span>), where if the value is an integer, it will append the px automatically. The width and height properties are more forgiving (either type works). These are the main differences in the jQuery:</p>



<div class="wp-block-codemirror-blocks-code-block code-block"><pre class="CodeMirror" data-setting="{&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:true,&quot;readOnly&quot;:true,&quot;language&quot;:&quot;JavaScript&quot;,&quot;modeName&quot;:&quot;js&quot;}">var x = &quot;90&quot;;
var y = &quot;120&quot;
$(selector).css( { left: x, top: y } ); //does NOT work!
$(selector).css( { left: x + &quot;px&quot;, top: y + &quot;px&quot; } ); //does work!

x = 90;
y = 120;
$(selector).css( { left: x, top: y } ); //does work!</pre></div>



<p>Have fun in jQuery!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/set-topleft-of-an-element-with-the-position-relative-to-the-parent-in-jquery/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">213</post-id>	</item>
	</channel>
</rss>
