Skip to content

Instantly share code, notes, and snippets.

@mattbarackman
Forked from dbc-challenges/jquery_quiz.js
Last active December 18, 2015 08:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattbarackman/5751199 to your computer and use it in GitHub Desktop.
Save mattbarackman/5751199 to your computer and use it in GitHub Desktop.
/* Here is your chance to take over Socrates!
Spend 10 minutes on each of the following hacks to the socrates website.
Enter them in the console to make sure it works and then save
your results here.
Choose a new pair for each. Add your names to the section you complete.
*/
/*1. Use basic selectors (id, class, element) to choose an element on the page.
Use the .css() method to alter at least two CSS properties of this element. */
$('#challenge_controls').on('mouseenter', '.btn-primary', function(){$(this).css('background-color', 'red')});
$('#challenge_controls').on('mouseenter', '.btn', function(){$(this).text("You've been H4cked!")});
$('#challenge_controls').on('mouseleave', '.btn', function(){$(this).text("Submit your gist")});
/*2. Use basic selectors and the find() method to select an image on the page
and change it with another image of your choice. */
/* On page http://socrates.devbootcamp.com/cohorts/15 */
$("img[alt='Maria Pacana']").attr('src','https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcSdqeRa0fbUX0Tbvq8GWwYAsf7LY2I0u-Mo7YgR7QI7RW6Ck1tzqw')
$("img[alt='Maria Pacana']").css('width', '96px')
$("img[alt='Maria Pacana']").css('height', '96px')
/*3. Use traverse methods to select all instances of a repeated word on the page
(like code) and use the animate() method to modify it.
*/
/* On page http://socrates.devbootcamp.com/labs/javascript/introduction/introduction */
function SubTextInAllElements(originalText, newText)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0; i < allElements.length; i++)
{
if (allElements[i].innerHTML == originalText)
{
// Element exists with attribute. Add to array.
allElements[i].innerHTML = newText;
}
}
}
SubTextInAllElements('Introduction', 'Cool Haxs')
/*4. Try to find an element that requires at least three selectors / traverse
methods to locate it and then use the .on() method to bind an event handler
on these elements (use an event other than click).*/
('#feed').children('.feed-item:nth-child(1)').find("p a[rel=nofollow]").on('mouseenter',function() {console.log("MOUSED OVER")});
/*5. Your choice. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment