admin管理员组文章数量:1310169
I have headers like
<h3 class="left_header">First job partner</h3>
<h3 class="left_header" style="text-align:center;">Don't have an account ?</h3>
Now i want to replace the first header with Job partner. how to do it by jQuery or Java script.
I have headers like
<h3 class="left_header">First job partner</h3>
<h3 class="left_header" style="text-align:center;">Don't have an account ?</h3>
Now i want to replace the first header with Job partner. how to do it by jQuery or Java script.
Share Improve this question asked Apr 21, 2014 at 10:45 UI DevUI Dev 6993 gold badges9 silver badges32 bronze badges 4- 1 Show what you have already tried. – Yury Tarabanko Commented Apr 21, 2014 at 10:47
-
I have tried like this..
jQuery(".left_header h3").html("Public offers");
but it didn't worked. I need to change first one only – UI Dev Commented Apr 21, 2014 at 10:48 -
.left_header h3
means "select all h3 having parent with class left_header". What you need is "select first h3 having class left_header" which translates toh3.left_header:first
. HTH – Yury Tarabanko Commented Apr 21, 2014 at 10:50 - jQuery("h3.left_header:first") not jQuery(".left_header h3") – Bhojendra Rauniyar Commented Apr 21, 2014 at 10:51
7 Answers
Reset to default 3Try to grab the h3
tags with the class .left_header
and take the first instance from the element collection using :first
selector,
$('h3.left_header:first').text('Job partner')
DEMO
Try this:
$('h3:first-child').html('sublink_active');
Working Demo
Try this
$("h3:first-child").html("Job Partner")
demo
try with this.
$(".left_header:first").html("yourNewTitle");
JQuery :
$('.left_header').first().text("Job Partner");
you can use.first()
(http://api.jquery./first/)
$( "h3" ).first().html("Job partner");
OR
you can use jQuery( ":first" )
(https://api.jquery./first-selector/)
$(".left_header:first").html("Job partner");
fiddle
Your code :
jQuery(".left_header h3").text("Public offers");
your code didn't match with your requirement. Because above code select all h3 elements under the "left_header" class. And In your HTML h3
have an class left_header
. So you should use following selector to select elements-
$("h3.left_header");
Now you want to select only first element, so you can use index number like this -
document.getElementsByClassName("left_header")[0].innerText = "Job Partner";
OR
var g = $("h3.left_header");
$(g[0]).text("Job Partner");
Demo1
Demo 2
Note: There are more than one way exist to acplish this task-
$(".left_header:first").text("Job Partner");
Working demo 1
本文标签: javascriptReplace the first header text with jqueryStack Overflow
版权声明:本文标题:javascript - Replace the first header text with jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741833950a2400102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论