CodingTrain / website-archive

Archive of the Coding Train website (first version)
https://codingtrain.github.io/website-archive/
MIT License
5.72k stars 5.65k forks source link

Uncaught TypeError: this.parent is not a function #779

Closed Yilu-Wang closed 5 years ago

Yilu-Wang commented 6 years ago

When I create the mousePressed function and use "this" referring to the element that triggers it, I always got the problem : this.sth is not a function.‬ It never happened before when I use "this" in the mousePressed function, which really confused me. ( By the way, Thank you for your helpful videos^_^

My code is attached below:

function setup() { noCanvas();

for(var i = 0; i < 3; i++){

var p = createP("This is a:"); p.style("background","#539124"); p.style("padding","30px"); p.style("color","#fff");

var li = createA("#","apple"); li.mousePressed(addPic); li.parent(p); } }

function addPic(){ var pic = createImg("apple.png"); pic.size(100,100); var paragraph = this.parent(); pic.parent(paragraph); }

function draw() { }

shiffman commented 6 years ago

Looks like you have run into this issue! Try using an earlier version of p5 (for now).

https://github.com/processing/p5.js/issues/3260 https://editor.p5js.org/codingtrain/sketches/rkbxI2Njm

gruselhaus commented 5 years ago

Looks like it was fixes with https://github.com/processing/p5.js/pull/3261

Working demo: https://editor.p5js.org/gruselhaus/sketches/UHnQGKa81