Reputation: 699
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.
Upvotes: 3
Views: 853
Reputation: 15490
you can use.first()
(http://api.jquery.com/first/)
$( "h3" ).first().html("Job partner");
OR
you can use jQuery( ":first" )
(https://api.jquery.com/first-selector/)
$(".left_header:first").html("Job partner");
Upvotes: 2
Reputation: 8161
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");
Note: There are more than one way exist to accomplish this task-
$(".left_header:first").text("Job Partner");
Upvotes: 1
Reputation: 11154
try with this.
$(".left_header:first").html("yourNewTitle");
Upvotes: 2
Reputation: 67207
Try 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')
Upvotes: 3