Svelte + jQuery hybrid framework/library
SvQuery is essentially a subsset of Svelte mixed together with jQuery.
IMPORTANT: Not ready for production use yet.
Almost all methods return the this
of the SvQuery element allowing you to link many methods together for example:
$("div").html("hello world").css("color: red").appendTo(document.body)
Most methods should be directly accessible $("input").input
however you can also do $("input").native.input
to access the property from the raw element
$("#myId")
$(".myClass")
$("*div")
// select all div elements that have the "myClass" class
$("*div && .myClass")
// select all elements that have either have "class1" or "class2"
$(".class1 || .class2")
// select all <a> tags that are inside of an <div> that are also inside of an element that has the "example" class
var els = $(".example > *div > *a")
// select all elements that have class1 or both class2 and class3 and that are also inside of a <div> element
$("*div > .class1 || (.class2 && .class3)")
$("div") // create an element of a native type
el.html() // returns the innerHTML
el.html("Example test") // sets the innerHTML
el.text() // returns the textContent
el.text("Example test") // sets the textContent
// using string of css code
el.css(`
color: red;
font-size: 18px;
font-family: sans-serif;
border: 2px dashed blue;
`)
// using object of key/value pairs
.css({
color: "red",
fontSize: "18px",
fontFamily: "sans-serif",
border: "2px dashed blue"
})
el.appendTo(document.body)
el.append(anotherEl)
el.addClass("example-class1", "example-class2")
el.removeClass("example-class1", "example-class2")
el.setId("example-id")
el.attr("width", "400")
el.attr({width: 400})
Note: addEventListener doesn't work on SvQuery elements, you must use the .on
method.
el.on("mouseup", function (e) {
console.log("hello", e);
});
$.getJSON("https://example.com/API/endpoint", function (data) {
console.log(data);
});
data = await $.getJSON("https://example.com/API/endpoint");
$.getJSONP("https://example.com/API/endpoint", function (data) {
console.log(data);
});
<!-- ### Parsing strings as psuedo-template literals
```js
$.template("My name is ${name}", {name: "Bob"});
``` -->