I think it is fair to say that this is the least of our concerns at this stage. Does it do what you expect, as @zystvan asked? How, on such a small project does one improve anything or make it more efficient or easier to read? Not really much we can do in that regard.
This is the sort of project that we can play around with a number of different ways for the practice. Say for instance someone were to say, “It would be easier to read if you wrote the value into a variable.”
$url = $(this).val();
$('.meme img').attr('src', $url);
Now it is clear what we are passing to the
src attribute. Not much different from yours, but how some programmers may prefer to write it.
Notice in this one I use a
blur event so nothing happens until the complete URL is typed in and the user clicks away from that form element? That’s another consideration. We don’t want the browser requesting a whole raft of incomplete URL’s.
Another consideration is specificity. In the above I zero in on the image by including its parent class. This would be just in case there are other images that we do not wish to affect by a general rule such as yours.
If there happened to be other elements with
.bottom-caption we could up the ante by specifying the element:
$txt = $(this).val();
It’s moot, here, but as your project grows…
Then we could go all out and try our hand at DOM tree traversal. What an experiment that would make. All in the name of learning, mind. The above is rather efficient in real terms.
You see where I’m going with this? There is so much subjectivity in programming that we cannot hope to completely elliminate it from our perspective. Granted, we should limit it, and having a style guide and a best practices guideline are how we can do that, but it is still up to us in the end.
Now is the time to learn the tools and syntax and usage. When it comes time to write for production we don’t want to be held up because there are holes in our knowledge base left there while we were chasing around trying to learn best practices. Focus on the knowledge base, for now and the rest will fall into place.