www.webdeveloper.com
Results 1 to 3 of 3

Thread: javascript, using this

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    javascript, using this

    Hi all, I would like to ask you for help, I'm generally of the paralytic in JavaScript, a little know how other programming languages​​, I wrote something like this up and running, (happily):
    Code:
    	function czerwony(wskaznik)
    	{
    	document.getElementById(wskaznik).style.color='#FF0000';
    	}
    	function czarny(wskaznik)
    	{
    	document.getElementById(wskaznik).style.color='#000000';
    	}
    
    //use:
    <p id='akapit' onmouseover="czerwony('akapit')" onmouseout="czarny('akapit')" >blablablablablablablabla</p>
    but if someone could help me write something with this? something like that:
    Code:
    	function czerwony(wskaznik)
    	{
    	wskaznik.style.color='#FF0000';
    	}
    	function czarny(wskaznik)
    	{
    	wskaznik.style.color='#000000';
    	}
    //use:
    <p onmouseover="czerwony('this')" onmouseout="czarny('this')" >blablablablablablablabla</p>
    and ideally should work as:
    Code:
    	function czerwony()
    	{
    	this.style.color='#FF0000';
    	}
    	function czarny()
    	{
    	this.style.color='#000000';
    	}
    	
    //użycie:
    <p onmouseover="czerwony()" onmouseout="czarny()" >blablablablablablablabla</p>
    Tell me, you can do something like that, or not much? and used this as the last code tag does not indicate (object) who called the function? or from the body of the function is a simple pointer to the object that caused it, or just look like in the first code? Is it possible to pass a pointer to an object by the argument of the function (as in the second example)?

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    You're so close!

    Code:
    	function czerwony(element)
    	{
    	element.style.color='#FF0000';
    	}
    	function czarny(element)
    	{
    	element.style.color='#000000';
    	}
    	
    //use:
    <p onmouseover="czerwony(this)" onmouseout="czarny(this)" >blablablablablablablabla</p>

  3. #3
    Join Date
    Nov 2012
    Posts
    2
    oooo
    thank you very much!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles