Loading...
Copy code
Close
Permalink
Close
Please tell us why you want to mark the subject as inappropriate.
(Maximum 200 characters)
Report Inappropriate
Cancel
Private Message
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Cancel
From :
guest
To :
Subject :
Content :
Type the characters you see in the picture below.
Send
Update
Cancel
Feedback
Email ID
Subject :
Comments :
Send
Cancel
Private Message
Type the characters you see in the picture below.
Type the characters you see in the picture below.
Attach files
Desktop
Google Docs
Each Attachment size should not exceed 1.0 MB.
Max no of attachments : 3
Loading User Profile...
guest
Response title
This is preview!
Attachments
Publish
Back to edit
Cancel
(
)
Sign In
New to this Portal? Click here to
Sign up
You can also use the below options to login
Login with Facebook
Login with Google
Login with Yahoo
jQuery
Plugins
UI
Meetups
Forum
Blog
About
Donate
All Forums
Recent Posts
Log In
Search
jQuery
Search
jQuery Forum
Move this topic
Forum :
Getting Started
Using jQuery
Using jQuery Plugins
Using jQuery UI
Developing jQuery Core
Developing jQuery Plugins
Developing jQuery UI
QUnit and Testing
About the jQuery Forum
jQuery Conferences
jQuery Mobile
Developing jQuery Mobile
Sub forum :
Move this topic
Cancel
Using jQuery
thestring
Replacing the html on a clicked button with closest()
in
Using jQuery
•
9 years ago
I have this html and jquery
<!Doctype>
<head>
<meta charset="utf-8" />
<title>Array Crud With Positions</title>
<style type="text/css">
.container{
width:960px;
}
.krudSpace{
width:100%;
}
label{
width:15%;
float:left;
}
.krudItem{
border:1px solid orange;
background-color:pink;
margin-bottom:2%;
}
button{
margin-right:2%;
margin-bottom:0.55%;
}
</style>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
jQuery(function() {
$("#button").click(function () {
$("<div class='krudItem' id='xxx'><form class='aj' name='itemForm' method='post' action=''><section><label>Slider Title</label><input type='hidden' name='sliderKey' value='16'/><input type='hidden' name='sliderPosition' value='12'/><input type='hidden' name='clickedButton' value='initial'/><input type='text' name='sliderTitle' value='lorem'/></section><section><label>Slider Location</label><input type='text' name='sliderLocation' value='ipsum'/></section><section><label>Slider Description</label><textarea name='sliderDescription'>hello world</textarea></section><button name='saveNew' class='saveNew' value='saveNew'>save</button><button name='newCancel'>cancel</button></form></div>").appendTo('.krudSpace');
});
//save new
jQuery('.saveNew').live("click",function(e)
{
e.preventDefault();
jQuery.ajax({
type: "POST",
url: "insert.php",
data: jQuery(".aj").serialize(),
success: function(data){
jQuery(this).closest('#xxx').replaceWith(data);
}
});
return false;
});
});
</script>
</head>
<body>
<button id="button">New</button>
<div class="container">
<div class="krudSpace" id="ks">
</div>
</div>
</body>
</html>
and this is the php
<?php
/**
test if replaced item can post and be deleted
@move ---->next
*/
$sliderKey = $_POST['sliderKey'];
$sliderPosition = $_POST['sliderPosition'];
$sliderTitle = $_POST['sliderTitle'];
$sliderLocation = $_POST['sliderLocation'];
$sliderDescription = $_POST['sliderDescription'];
echo "<div class='krudItem' id='xxx'><form class='aj' name='itemForm' method='post'action=''><section><label>Slider Title</label><input type='hidden' name='sliderKey' value='$sliderKey'/><input type='hidden' name='sliderPosition' value='$sliderPosition'/><input type='text' name='sliderTitle' value='$sliderTitle'/></section><section><label>Slider Location</label><input type='text' name='sliderLocation' value='$sliderLocation'/></section><section><label>Slider Description</label><textarea name='sliderDescription'>THIS IS THE REPLACEMENT</textarea></section><button name='saveNew' class='saveNew'>save</button><button name='newCancel'>delete</button></form></div>";
?>
I am trying to replace the item that helped me post to the php script using the data returned from post
success: function(data){
jQuery(this).closest('#xxx').replaceWith(data);
}
but it doesn't work.How will i fix this?.
1
Replies(1)
jakecigar
Re: Replacing the html on a clicked button with closest()
9 years ago
this
is not what you want. Since ids are unique, this will do
$('#xxx').replaceWith(data)
JΛ̊KE
Leave a comment on jakecigar's reply
Change topic type
Topic Type :
Discussions
Questions
Ideas
Problems
No of days :
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
Change topic type
Cancel
Link this topic
Provide the permalink of a topic that is related to this topic
Permalink
Save
Close
Reply to thestring's question
Top
Reply
{"z20772489":[14737000003595208],"z2950240":[14737000003596439]}
Statistics
1
Replies
2252
Views
1
Followers
Tags
Cancel
closest
replacewith
Actions
Permalink