<?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>jquery &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/jquery/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Tue, 14 Apr 2020 17:58:15 +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>jquery &#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>Javascript equivalent to PHP __construct</title>
		<link>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/</link>
					<comments>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Thu, 16 Apr 2020 17:36:00 +0000</pubDate>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[class-constructor]]></category>
		<category><![CDATA[construct]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[constructor-function]]></category>
		<category><![CDATA[constructor-method]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[javascript-class]]></category>
		<category><![CDATA[javascript-construct]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[php-like]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scripting]]></category>
		<guid isPermaLink="false">https://www.maxvergelli.com/?p=245</guid>

					<description><![CDATA[Constructor method in Javascript class equivalent to PHP, how to run a function in Javascript whenever the object is instantiated.]]></description>
										<content:encoded><![CDATA[
<p>The <code>constructor</code> method is a special method for creating and initializing an object created within a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/class"><code>class</code></a>. In other words, it&#8217;s a function that runs automatically whenever the object is instantiated.</p>



<p><strong>Using the <code>constructor</code> method</strong></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;}">class Person {

  constructor(name) {
    this.name = name;
  }

  introduce() {
    console.log(`Hello, my name is ${this.name}`);
  }

}

const otto = new Person('Otto');

otto.introduce();</pre></div>



<p>If you don&#8217;t provide your own constructor, then a default constructor will be supplied for you. If your class is a base class, the default constructor is empty:</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;}">constructor() {}</pre></div>



<p>If your class is a derived class, the default constructor calls the parent constructor, passing along any arguments that were provided:</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;}">constructor(...args) {
  super(...args);
}</pre></div>



<p>Just as a reminder: the <strong>super</strong> keyword is used to access and call functions on an object&#8217;s parent (more information here <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super" class="aioseop-link">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/super</a>)</p>



<p>Look at these other resources on <strong>Javascript constructor</strong>:</p>



<p><a href="https://stackoverflow.com/questions/61213185/javascript-equivalent-to-php-construct">https://stackoverflow.com/questions/61213185/javascript-equivalent-to-php-construct</a></p>



<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/javascript-equivalent-to-php-__construct/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">245</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>
