Attribute jquery

Estimated reading time: 1 minute

Attribute & content

href, src, id, class, style

$(function() {
  var val = $("a").attr("href");
  alert(val);
});

removeAttribute

$(function() {
    $("table").removeAttr("border");
    $("table").removeAttr("class");
});

content

  • retrive html
$(function() {
  var val = $("p").html();
  alert(val);
});
  • retrive text
$(function() {
  var val = $("p").text();
  alert(val);
});
  • retrive input value
$(function() {
  alert($("#name").val());
});

add content

  • append() inserts content at the end of the selected elements.
  • prepend() inserts content at the beginning of the selected elements.
  • after() inserts content after the selected elements.
  • before() inserts content before the selected elements.
$(function() {
    $("#demo").append("kamal");
});
$(function() {
    $("#demo").prepend("David kamal");
});
$(function() {
    $("#demo").before("<i>this is before</i>");
    $("#demo").after("<b>after ending</b>");
});
js, jquery