Note to Self 10 – JQuery Selectors and Custom Functions and a thought on JQuery
After using Python, diving into jQuery has proven exceptionally difficult. Even though it solves the not-so-small problem of commonizing the DOM across multiple browsers, I find it very difficult to read. I know with time I’ll get used to it and maybe even find some beauty in my jQuery code, but it will never stop me from wishing for a cleaner syntax like that of Python or Ruby.
With that said, here’s a bit of what I learned about jQuery recently.
- Selectors in jQuery are a syntax for selecting an html element. Selectors can return a single element or several (or none if nothing matching is found).
- $(“#[elementID]”) – finds an element with an id attribute equal to “elementID”.
- $(“[name=’elementName’]”) – gets all elements with a name attribute equal to “elementName”
- $(“[name^=’element’]”) – gets all elements with a name attribute that begins with “element”
- $(“[name$=’Name’]”) – gets all elements with a name attribute that ends with “Name”
- $(“input:checkbox”) – gets all checkboxes
- $(“#blah > input:checkbox”) – gets all checkboxes within a parent element of id “blah”
- Creating a custom function in jQuery:
$.fn.CustomFunctionName({function()({
//code here
})$.fn.exclaim = function(message){
alert(message)
}
$.fn.exclaim("hello, world")
Labels: jQuery






0 Comments:
Post a Comment
<< Home