Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery code selector

Tags:

jquery

I have this code that someone else wrote and am wondering, what this jQuery code is selecting? Is this valid jQuery code?

var a = $("<h3/>").append($("<a/>", {
    href  : "/comic/title.html",
    class : "comic-link"
}).text("comic-name"));

I have never seen HTML tags being used like <h3/> or <a/>.

like image 934
DavidL Avatar asked Dec 13 '11 18:12

DavidL


People also ask

What does $( div p select?

"$("div p")" Selects all elements matched by <div> that contain an element matched by <p>.

How do I select something in jQuery?

The select() method is an inbuilt method in jQuery which is used when some letters or words are selected (or marked) in a text area or a text field. Syntax: $(selector). select(function);


2 Answers

The above snippet does not select anything, it creates DOM elements and subsequently manipulates them.

See here for the jQuery documentation of this method.

like image 146
Rich O'Kelly Avatar answered Sep 21 '22 17:09

Rich O'Kelly


  1. $("<h3/>" creates a new h3 element
  2. $("<a/>", { attributes}) creates an <a/> with those attributes
  3. .text() appends the text
  4. var a = the whole un-attached newly created DOM element (wrapped in a jQuery object)
like image 23
DefyGravity Avatar answered Sep 20 '22 17:09

DefyGravity