Skip to content

Instantly share code, notes, and snippets.

@VPAbraham
Last active August 26, 2019 16:49
Show Gist options
  • Select an option

  • Save VPAbraham/7a21473310c17a36add0543c2ae55272 to your computer and use it in GitHub Desktop.

Select an option

Save VPAbraham/7a21473310c17a36add0543c2ae55272 to your computer and use it in GitHub Desktop.
jQuery Jigsaw Research

jQuery Jigsaw

Getting and Setting Content Values Using jQuery methods:

  • How do you get the text from an element (say a paragraph element)?
$('.elem').text();
  • How do you set the text from an element (say a paragraph element)?
$('.elem').text('Your text here');
  • How do you get the text from an input element?
$('elem').val();
  • How do you set the text from an input element?
$('elem').val(value);
  • How do you add, remove, or toggle classes of HTML elements?
$('elem').addClass('yourClass');

$('elem').removeClass('yourClass');

$('elem').toggleClass('yourClass');
  • How can you tell if an HTML element contains a certain CSS class?
$('elem').hasClass('className');
  • What happens when you select and element using vanilla JavaScript (document.querySelector()) and then try to use a jQuery method for getting the text of that element? Provide examples of this and what errors you see.

It does not correctly select the element. Seems that jQuery methods will only work on jQuery objects.

  • If you have a jQuery selector that returns multiple elements, say $('.link-img'), then do you need to use a for loop to change the elements? Why or why not? What is returned by the selector?

No, all elements falling under these classes will have the same methods run on them simultaneously.

  • Create a demo (in CodePen) getting the text and setting the text of different elements.

    Codepen Demo

  • Where do you go to find the official jQuery docs? On this doc page, there are two parts of the page, each with a black header: one text() and the other text( text ). jQuery API Documentation

  • What is the purpose of these two different sections?

I can't find this particular site.

  • Can you find other examples where a page is written/organized in this way?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment