티스토리 뷰
Content 받아오기
- text()
- html()
$(document).ready(function(){
$("#btn1").click(function(){
alert("Text: " + $("#test").text());
});
$("#btn2").click(function(){
alert("HTML: " + $("#test").html());
});
});
- val()
- 자바스크립트에서 document.getElementById("id").value 를 간략하게 만든 것이다
$(document).ready(function(){
$("button").click(function(){
alert("Value: " + $("#test").val());
});
});
- attr() : attribute values를 받아온다
$(document).ready(function(){
$("button").click(function(){
alert($("#w3s").attr("href"));
});
});
Content 세팅하기
- text("text to set")
- html("html content to set")
- val("value to set")
Callback function
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#test1").text(function(i, origText2){
return "Old text: " + origText2 + " New text: Hello world! (index: " + i + ")";
});
});
$("#btn2").click(function(){
$("#test2").html(function(i, origText2){
return "Old html: " + origText + " New html: Hello <b>world!</b> (index: " + i + ")";
});
});
});
</script>
</head>
<body>
<p id="test1">This is a <b>bold</b> paragraph.</p>
<p id="test2">This is another <b>bold</b> paragraph.</p>
<button id="btn1">Show Old/New Text</button>
<button id="btn2">Show Old/New HTML</button>
</body>
</html>
- attr()
사용 예시) $("#id")attr("href", "new_url");
'jQuery > html' 카테고리의 다른 글
jQuery: CSS classes, dimensions (0) | 2020.07.31 |
---|---|
jQuery: add, remove (0) | 2020.07.31 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- DB4free
- html
- HTML #CSS
- 인용문 #주석
- HTML #Tables
- UserBean
- Mavenproject
- text_shadow
- JSP_CRUD
- Block_element #inline_element
- annotation
- HTML #Headings #Paragraph #Styles
- HTML #class
- css
- links lists tables display
- HTML_Forms
- 2020Camp
- box_model
- STS4
- JSP환경구축
- HTML #media #video #YouTube
- javascript #datatype
- HTML #id #iframe
- HTML #Canvas #SVG
- meta #link #script #base #HTML
- head #title #style
- HTML_Formatting
- fontstyle
- jsp
- DynamicWebProject
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함