Question

Question 1. Show the correct jQuery code for each of the following UI tasks: a) Select...

Question 1.

Show the correct jQuery code for each of the following UI tasks:

a) Select all elements with class="name" and give each of them a unique id in the form "name-0", "name-1", "name-2"… and so on

b) Anytime an element with class="trackClick" is clicked (using the "click" event), output the text "element clicked" to the console (using console.log()). This must work for all present and future elements with the class "trackClick".

Question 2.

Assume that there is only one <table> in the DOM tree and the table hast at least one row with five columns. Write down a small JavaScript code fragment to add one row to this table.

Question 3.

Write a JavaScript function that deletes all <image> tags from the screen.

Question 4.

Develop a JavaScript function that takes a DOM element as argument and reverses the order of its children, i.e. first child becomes last child, second child becomes one before last child, etc.

Question 5.

Consider the following code fragment:

Write a piece of code in JavaScript to remove all the styles from the web-page.

Question 6.

Write down a JavaScript expression to remove all the rows of a <table>. Assume that there is ONLY one table in the page and that the table has at least one row with at least one column (the exact number of columns is unknown to us).

Question 7.

Develop a JavaScript function that takes a DOM element as argument and reverses the order of its children, i.e. first child becomes last child, second child becomes one before last child, etc. (This question in duplicated from Test Two)

Question 8.

In the following code fragment, modify the style of the paragraph text using JavaScript code. Clicking on the button the font size and color of the paragraph text will be changed.

Question 9.

Look at the following code fragment. Write a JavaScript program to removes items from a dropdown list one at a time.

Question 10.

Write down a JavaScript code that turns the color of all <p> tags to “Red”.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As we are allowed to answer only four sub parts, please post new question for remaining questions.

1a)

var id=0;

$(".name").each(function(){
   $(this).attr('id', 'name'+id);
id++;
})

Sample screenshot:

HTML ▼ 1 <div class-mbox>Block One</div 2 <div class-mbox>Block Two</div 3 <div class-mbox>Block Three</div> 4 <div class-mbox>Block Four</div:> Block One Block Two Block Three Block Four JavaScript + jQuery 1.9.1 ▼ 1 var id -0 ▼ $(.mbox).each(function(){ S(this).attr(id, name +id); 3) 25 Timelines Edi panel h panel resultsPanel B frame D document 0 Resources B div#editor Network Debugger Storage ullyLoaded form#show result C div#content div panel v right html B body B div#name class-mbox id-name0>Block One</div>$0 class-mbox id-name1 Block Two</div> class-mbox id-name2 Block Three</div> class-mbox id-name3>Block Four</div>

1b)

$('body').on('click', '.trackClick', function(event) { 
console.log("element clicked");

}

Live takes care of future elements as well.

2)

$('#myTable tr:last').after('<tr><td/> <td/> <td/> <td/> <td/> </tr>');

myTable is the id of the table. It adds a row with 5 columns at the end.

3)

function removeImages() {

var images = document.getElementsByTagName('img');
var l = images.length;
for (var i = 0; i < l; i++) {
    images[0].parentNode.removeChild(images[0]);
}

}

4) Reversing dom elements

function reverse(n) {          // Reverse the order of the children of Node n
    var kids = n.childNodes;   
    var numkids = kids.length; 
    for(var i = numkids-1; i >= 0; i--) {  
        var c = n.removeChild(kids[i]);    //Remove child from lastand append from first
        n.appendChild(c);                  
    }
}

Here I answered you 5 sub parts. In case of any doubts, please comment.

Add a comment
Know the answer?
Add Answer to:
Question 1. Show the correct jQuery code for each of the following UI tasks: a) Select...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Javascript to edit a HTML file. Where to begin? <!doctype html> <html>    <head>      <meta charset="utf-8">      <title>TODO:...

    Javascript to edit a HTML file. Where to begin? <!doctype html> <html>    <head>      <meta charset="utf-8">      <title>TODO: Change The Title</title>    </head>    <body>      <h1></h1>      <p>First paragraph.</p>      <p class="intro">Second <span>paragraph</span>.</p>      <button id="start">Start</button>      <main> </main>      <!--       Test 6: DOM Programming       You MAY consult the notes for week 7, but you MAY NOT discuss this test or       your code with any other students.  All work must be your own.       Instructions:              1. Put all solution code in a file named solution.js.  When you upload your          solution to...

  • 1. Site Header (10 points) As a top-level header (h1) put your name, left aligned In the upper-ri...

    1. Site Header (10 points) As a top-level header (h1) put your name, left aligned In the upper-right corner of the page, put a div with a large text size (about h1 size) a. b. i. This div should have a black background and white text ii. In this div, you should put the step number that you believe to have completed of the quiz, updating it before you submit All of the rest of the elements shall be left-aligned....

  • i need help with this homework webpage and code too: The webpage must include: Global Structure...

    i need help with this homework webpage and code too: The webpage must include: Global Structure Tags Text Tags Images   Your first page must be named index.html Include a table within your site, challenge yourself to add a header in the table, and choose interesting border and/or cell formatting. Include a hyperlink within your site. Include an image in your site. Include a form in your site to demonstrate understanding of a variety of form components (the form does not...

  • Javascript each item must have at least three categorical attributes and at least one numeric attribute....

    Javascript each item must have at least three categorical attributes and at least one numeric attribute. Attributes such as ID, name etc do not count as categorical or numeric attributes. Exercise 1 (a) Define a class for your item that meets the above three categorical and one numeric attribute requirements. (b) Create a text file that contains at least 5 such records in CSV format. (c) Create a HTML page that contains a table element the shows one item record...

  • Question 1: Given the following HTML code segment <p>While this is a <b> very basic HTML...

    Question 1: Given the following HTML code segment <p>While this is a <b> very basic HTML document </b>, it actually serves as a detailed example of the document object model. </p> How many text nodes will be added to the DOM tree to represent the structure of text content in this HTML code segment A. 1 B. 2 C. 3 D. 4 Question 2: Assume in an HTML document named “index.html”, the following <script> element is added <script src="grocery.js"></script> This...

  • Question 52 (1 point) Write the missing code in the following code fragment to check the...

    Question 52 (1 point) Write the missing code in the following code fragment to check the input using method of the Scanner class. This fragment is intended to read from a text file. Scanner in = new Scanner(...); while double hours = in.nextDouble(); System.out.println (hours); D] Previous Page Next Page Page 52 of 52

  • JavaScript Question: Select only the second element with the class '.container'. Assign it to a variable...

    JavaScript Question: Select only the second element with the class '.container'. Assign it to a variable named `container`. Code snippets of the sections with "container:" <nav class="navbar navbar-expand-lg"> <div class="container"> <a title="someUniversity" class="navbar-brand order-1 mr-0" href="#" target="_blank">Presented by someUniversity JavaScript Course</a> <div class="" id="navbarNavAltMarkup"> <div class="navbar-nav"> <a class="nav-item nav-link" href="#home">Home <span class="sr-only">(current)</span></a> <a class="nav-item nav-link" href="#about">About</a> <a class="nav-item nav-link" href="#speakers">Speakers</a> <a class="nav-item nav-link" href="#schedule">Schedule</a> </div> </div> </div> <div class="jumbotron jumbotron-fluid text-white"> <div class="container text-sm-center pt-5"> <h1 class="display-2">JavaScript Conference</h1> <p class="lead">A...

  • circle the correct answer please. Please reply Asap. 8. What does the following jQuery code do?...

    circle the correct answer please. Please reply Asap. 8. What does the following jQuery code do? s ("inage").attr(are", imagoURL) a Gets the value of the sre aribute for the element with an id of "image" and stores it in a variable named imageURL Sets the value of the sre attribute for the element with an id of "image" to the value in a variable named imageURL Gets the values of the sre attribute for each element with a class of...

  • URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to...

    URGENT HELP NEEDED: JQuery. PLEASE POST SCREEN SHOTS Task 1: Downloading jQuery Right-click the link to download the uncompressed latest version of jQuery Copy the jQuery.x.x.x.js file in the folder and specified as source file. Task 2: Download and install HTML-Kit 1. Navigate to htmlkit.com. 2. Click Download HTML-Kit 292. After it downloads, launch HKSetup.exe. Choose Full installation (the default) Uncheck Yes, download and install HTML-Kit Tools Trial. 6. Click Next>Finish. Task 3: Creating a Simple jQuery Application Launch HTML-Kit....

  • Write a program that check odd / even numbers (from number 1 to 100). Display the...

    Write a program that check odd / even numbers (from number 1 to 100). Display the results within an HTML table with 2 columns: one for odd number and one for even numbers. NUMBERS RESULTS ODD EVEN ODD 2 HINT: use <table> tags to create a table, <th> tags for 'Numbers' and 'Results'. Wrap code PHP inside HTML code. For example: <html> <title>CHECK ODD or EVEN</title> <body> <table> ?php echo "<tr><td>l</td><td>Odd</td</tr>"; </table> </body </html 2. Do the following steps in...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT